@pooflabs/web 0.0.73 → 0.0.74

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.
Files changed (65) hide show
  1. package/dist/auth/index.d.ts +4 -5
  2. package/dist/auth/providers/mock-auth-provider.d.ts +3 -3
  3. package/dist/auth/providers/privy-expo-provider.d.ts +105 -0
  4. package/dist/{index-BFJJZKXQ.js → index-BVfqY0fJ.js} +2761 -7
  5. package/dist/index-BVfqY0fJ.js.map +1 -0
  6. package/dist/index-Bdcc5821.js +2375 -0
  7. package/dist/index-Bdcc5821.js.map +1 -0
  8. package/dist/{index-TfCOBCez.esm.js → index-ByH7PSr3.esm.js} +2756 -2
  9. package/dist/index-ByH7PSr3.esm.js.map +1 -0
  10. package/dist/index-CVK4iKo4.js +21508 -0
  11. package/dist/index-CVK4iKo4.js.map +1 -0
  12. package/dist/index-CrOVJFX9.esm.js +2373 -0
  13. package/dist/index-CrOVJFX9.esm.js.map +1 -0
  14. package/dist/index-ORXorrQK.esm.js +18291 -0
  15. package/dist/index-ORXorrQK.esm.js.map +1 -0
  16. package/dist/index-QqlKSXH4.js +18332 -0
  17. package/dist/index-QqlKSXH4.js.map +1 -0
  18. package/dist/index-tYJgJQDc.esm.js +21430 -0
  19. package/dist/index-tYJgJQDc.esm.js.map +1 -0
  20. package/dist/index.browser-B8vmX-tI.js +1471 -0
  21. package/dist/index.browser-B8vmX-tI.js.map +1 -0
  22. package/dist/{index.browser-ChrwVq76.esm.js → index.browser-C2K1wE09.esm.js} +2 -3
  23. package/dist/{index.browser-ChrwVq76.esm.js.map → index.browser-C2K1wE09.esm.js.map} +1 -1
  24. package/dist/index.browser-D63nJFKg.esm.js +1468 -0
  25. package/dist/index.browser-D63nJFKg.esm.js.map +1 -0
  26. package/dist/{index.browser-BuIgwfvv.esm.js → index.browser-DTId19-8.esm.js} +2 -3
  27. package/dist/{index.browser-BuIgwfvv.esm.js.map → index.browser-DTId19-8.esm.js.map} +1 -1
  28. package/dist/{index.browser-wsb8xknL.js → index.browser-De6JT7NR.js} +2 -3
  29. package/dist/{index.browser-wsb8xknL.js.map → index.browser-De6JT7NR.js.map} +1 -1
  30. package/dist/{index.browser-BO1XxDi0.js → index.browser-GM5fUBfQ.js} +2 -3
  31. package/dist/{index.browser-BO1XxDi0.js.map → index.browser-GM5fUBfQ.js.map} +1 -1
  32. package/dist/index.d.ts +4 -0
  33. package/dist/index.esm.js +1 -2
  34. package/dist/index.esm.js.map +1 -1
  35. package/dist/index.js +6 -2
  36. package/dist/index.js.map +1 -1
  37. package/dist/index.native-CzfZTw_J.esm.js +13211 -0
  38. package/dist/index.native-CzfZTw_J.esm.js.map +1 -0
  39. package/dist/index.native-muw49g7i.js +13290 -0
  40. package/dist/index.native-muw49g7i.js.map +1 -0
  41. package/dist/index.native.d.ts +24 -0
  42. package/dist/index.native.esm.js +6 -0
  43. package/dist/index.native.esm.js.map +1 -0
  44. package/dist/index.native.js +59 -0
  45. package/dist/index.native.js.map +1 -0
  46. package/dist/phantom-wallet-provider-CeNZvRZY.js +1328 -0
  47. package/dist/phantom-wallet-provider-CeNZvRZY.js.map +1 -0
  48. package/dist/phantom-wallet-provider-Di3Z8vOA.esm.js +1307 -0
  49. package/dist/phantom-wallet-provider-Di3Z8vOA.esm.js.map +1 -0
  50. package/dist/platform.d.ts +68 -0
  51. package/dist/privy-wallet-provider-Cfws3b3x.esm.js +3921 -0
  52. package/dist/privy-wallet-provider-Cfws3b3x.esm.js.map +1 -0
  53. package/dist/privy-wallet-provider-lbg2fDVg.js +3942 -0
  54. package/dist/privy-wallet-provider-lbg2fDVg.js.map +1 -0
  55. package/dist/solana-mobile-wallet-provider-BZMvp9Qy.esm.js +558 -0
  56. package/dist/solana-mobile-wallet-provider-BZMvp9Qy.esm.js.map +1 -0
  57. package/dist/solana-mobile-wallet-provider-DDqwl25J.js +579 -0
  58. package/dist/solana-mobile-wallet-provider-DDqwl25J.js.map +1 -0
  59. package/package.json +19 -3
  60. package/dist/index-BFJJZKXQ.js.map +0 -1
  61. package/dist/index-BV8MOXXy.js +0 -36033
  62. package/dist/index-BV8MOXXy.js.map +0 -1
  63. package/dist/index-D0yz-P8G.esm.js +0 -35962
  64. package/dist/index-D0yz-P8G.esm.js.map +0 -1
  65. package/dist/index-TfCOBCez.esm.js.map +0 -1
@@ -0,0 +1,2373 @@
1
+ var buffer = {};
2
+
3
+ var base64Js = {};
4
+
5
+ var hasRequiredBase64Js;
6
+
7
+ function requireBase64Js () {
8
+ if (hasRequiredBase64Js) return base64Js;
9
+ hasRequiredBase64Js = 1;
10
+
11
+ base64Js.byteLength = byteLength;
12
+ base64Js.toByteArray = toByteArray;
13
+ base64Js.fromByteArray = fromByteArray;
14
+
15
+ var lookup = [];
16
+ var revLookup = [];
17
+ var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
18
+
19
+ var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
20
+ for (var i = 0, len = code.length; i < len; ++i) {
21
+ lookup[i] = code[i];
22
+ revLookup[code.charCodeAt(i)] = i;
23
+ }
24
+
25
+ // Support decoding URL-safe base64 strings, as Node.js does.
26
+ // See: https://en.wikipedia.org/wiki/Base64#URL_applications
27
+ revLookup['-'.charCodeAt(0)] = 62;
28
+ revLookup['_'.charCodeAt(0)] = 63;
29
+
30
+ function getLens (b64) {
31
+ var len = b64.length;
32
+
33
+ if (len % 4 > 0) {
34
+ throw new Error('Invalid string. Length must be a multiple of 4')
35
+ }
36
+
37
+ // Trim off extra bytes after placeholder bytes are found
38
+ // See: https://github.com/beatgammit/base64-js/issues/42
39
+ var validLen = b64.indexOf('=');
40
+ if (validLen === -1) validLen = len;
41
+
42
+ var placeHoldersLen = validLen === len
43
+ ? 0
44
+ : 4 - (validLen % 4);
45
+
46
+ return [validLen, placeHoldersLen]
47
+ }
48
+
49
+ // base64 is 4/3 + up to two characters of the original data
50
+ function byteLength (b64) {
51
+ var lens = getLens(b64);
52
+ var validLen = lens[0];
53
+ var placeHoldersLen = lens[1];
54
+ return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
55
+ }
56
+
57
+ function _byteLength (b64, validLen, placeHoldersLen) {
58
+ return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
59
+ }
60
+
61
+ function toByteArray (b64) {
62
+ var tmp;
63
+ var lens = getLens(b64);
64
+ var validLen = lens[0];
65
+ var placeHoldersLen = lens[1];
66
+
67
+ var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
68
+
69
+ var curByte = 0;
70
+
71
+ // if there are placeholders, only get up to the last complete 4 chars
72
+ var len = placeHoldersLen > 0
73
+ ? validLen - 4
74
+ : validLen;
75
+
76
+ var i;
77
+ for (i = 0; i < len; i += 4) {
78
+ tmp =
79
+ (revLookup[b64.charCodeAt(i)] << 18) |
80
+ (revLookup[b64.charCodeAt(i + 1)] << 12) |
81
+ (revLookup[b64.charCodeAt(i + 2)] << 6) |
82
+ revLookup[b64.charCodeAt(i + 3)];
83
+ arr[curByte++] = (tmp >> 16) & 0xFF;
84
+ arr[curByte++] = (tmp >> 8) & 0xFF;
85
+ arr[curByte++] = tmp & 0xFF;
86
+ }
87
+
88
+ if (placeHoldersLen === 2) {
89
+ tmp =
90
+ (revLookup[b64.charCodeAt(i)] << 2) |
91
+ (revLookup[b64.charCodeAt(i + 1)] >> 4);
92
+ arr[curByte++] = tmp & 0xFF;
93
+ }
94
+
95
+ if (placeHoldersLen === 1) {
96
+ tmp =
97
+ (revLookup[b64.charCodeAt(i)] << 10) |
98
+ (revLookup[b64.charCodeAt(i + 1)] << 4) |
99
+ (revLookup[b64.charCodeAt(i + 2)] >> 2);
100
+ arr[curByte++] = (tmp >> 8) & 0xFF;
101
+ arr[curByte++] = tmp & 0xFF;
102
+ }
103
+
104
+ return arr
105
+ }
106
+
107
+ function tripletToBase64 (num) {
108
+ return lookup[num >> 18 & 0x3F] +
109
+ lookup[num >> 12 & 0x3F] +
110
+ lookup[num >> 6 & 0x3F] +
111
+ lookup[num & 0x3F]
112
+ }
113
+
114
+ function encodeChunk (uint8, start, end) {
115
+ var tmp;
116
+ var output = [];
117
+ for (var i = start; i < end; i += 3) {
118
+ tmp =
119
+ ((uint8[i] << 16) & 0xFF0000) +
120
+ ((uint8[i + 1] << 8) & 0xFF00) +
121
+ (uint8[i + 2] & 0xFF);
122
+ output.push(tripletToBase64(tmp));
123
+ }
124
+ return output.join('')
125
+ }
126
+
127
+ function fromByteArray (uint8) {
128
+ var tmp;
129
+ var len = uint8.length;
130
+ var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
131
+ var parts = [];
132
+ var maxChunkLength = 16383; // must be multiple of 3
133
+
134
+ // go through the array every three bytes, we'll deal with trailing stuff later
135
+ for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
136
+ parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
137
+ }
138
+
139
+ // pad the end with zeros, but make sure to not forget the extra bytes
140
+ if (extraBytes === 1) {
141
+ tmp = uint8[len - 1];
142
+ parts.push(
143
+ lookup[tmp >> 2] +
144
+ lookup[(tmp << 4) & 0x3F] +
145
+ '=='
146
+ );
147
+ } else if (extraBytes === 2) {
148
+ tmp = (uint8[len - 2] << 8) + uint8[len - 1];
149
+ parts.push(
150
+ lookup[tmp >> 10] +
151
+ lookup[(tmp >> 4) & 0x3F] +
152
+ lookup[(tmp << 2) & 0x3F] +
153
+ '='
154
+ );
155
+ }
156
+
157
+ return parts.join('')
158
+ }
159
+ return base64Js;
160
+ }
161
+
162
+ var ieee754 = {};
163
+
164
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
165
+
166
+ var hasRequiredIeee754;
167
+
168
+ function requireIeee754 () {
169
+ if (hasRequiredIeee754) return ieee754;
170
+ hasRequiredIeee754 = 1;
171
+ ieee754.read = function (buffer, offset, isLE, mLen, nBytes) {
172
+ var e, m;
173
+ var eLen = (nBytes * 8) - mLen - 1;
174
+ var eMax = (1 << eLen) - 1;
175
+ var eBias = eMax >> 1;
176
+ var nBits = -7;
177
+ var i = isLE ? (nBytes - 1) : 0;
178
+ var d = isLE ? -1 : 1;
179
+ var s = buffer[offset + i];
180
+
181
+ i += d;
182
+
183
+ e = s & ((1 << (-nBits)) - 1);
184
+ s >>= (-nBits);
185
+ nBits += eLen;
186
+ for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
187
+
188
+ m = e & ((1 << (-nBits)) - 1);
189
+ e >>= (-nBits);
190
+ nBits += mLen;
191
+ for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
192
+
193
+ if (e === 0) {
194
+ e = 1 - eBias;
195
+ } else if (e === eMax) {
196
+ return m ? NaN : ((s ? -1 : 1) * Infinity)
197
+ } else {
198
+ m = m + Math.pow(2, mLen);
199
+ e = e - eBias;
200
+ }
201
+ return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
202
+ };
203
+
204
+ ieee754.write = function (buffer, value, offset, isLE, mLen, nBytes) {
205
+ var e, m, c;
206
+ var eLen = (nBytes * 8) - mLen - 1;
207
+ var eMax = (1 << eLen) - 1;
208
+ var eBias = eMax >> 1;
209
+ var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
210
+ var i = isLE ? 0 : (nBytes - 1);
211
+ var d = isLE ? 1 : -1;
212
+ var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
213
+
214
+ value = Math.abs(value);
215
+
216
+ if (isNaN(value) || value === Infinity) {
217
+ m = isNaN(value) ? 1 : 0;
218
+ e = eMax;
219
+ } else {
220
+ e = Math.floor(Math.log(value) / Math.LN2);
221
+ if (value * (c = Math.pow(2, -e)) < 1) {
222
+ e--;
223
+ c *= 2;
224
+ }
225
+ if (e + eBias >= 1) {
226
+ value += rt / c;
227
+ } else {
228
+ value += rt * Math.pow(2, 1 - eBias);
229
+ }
230
+ if (value * c >= 2) {
231
+ e++;
232
+ c /= 2;
233
+ }
234
+
235
+ if (e + eBias >= eMax) {
236
+ m = 0;
237
+ e = eMax;
238
+ } else if (e + eBias >= 1) {
239
+ m = ((value * c) - 1) * Math.pow(2, mLen);
240
+ e = e + eBias;
241
+ } else {
242
+ m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
243
+ e = 0;
244
+ }
245
+ }
246
+
247
+ for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
248
+
249
+ e = (e << mLen) | m;
250
+ eLen += mLen;
251
+ for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
252
+
253
+ buffer[offset + i - d] |= s * 128;
254
+ };
255
+ return ieee754;
256
+ }
257
+
258
+ /*!
259
+ * The buffer module from node.js, for the browser.
260
+ *
261
+ * @author Feross Aboukhadijeh <https://feross.org>
262
+ * @license MIT
263
+ */
264
+
265
+ var hasRequiredBuffer;
266
+
267
+ function requireBuffer () {
268
+ if (hasRequiredBuffer) return buffer;
269
+ hasRequiredBuffer = 1;
270
+ (function (exports$1) {
271
+
272
+ const base64 = requireBase64Js();
273
+ const ieee754 = requireIeee754();
274
+ const customInspectSymbol =
275
+ (typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation
276
+ ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
277
+ : null;
278
+
279
+ exports$1.Buffer = Buffer;
280
+ exports$1.SlowBuffer = SlowBuffer;
281
+ exports$1.INSPECT_MAX_BYTES = 50;
282
+
283
+ const K_MAX_LENGTH = 0x7fffffff;
284
+ exports$1.kMaxLength = K_MAX_LENGTH;
285
+
286
+ /**
287
+ * If `Buffer.TYPED_ARRAY_SUPPORT`:
288
+ * === true Use Uint8Array implementation (fastest)
289
+ * === false Print warning and recommend using `buffer` v4.x which has an Object
290
+ * implementation (most compatible, even IE6)
291
+ *
292
+ * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
293
+ * Opera 11.6+, iOS 4.2+.
294
+ *
295
+ * We report that the browser does not support typed arrays if the are not subclassable
296
+ * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
297
+ * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
298
+ * for __proto__ and has a buggy typed array implementation.
299
+ */
300
+ Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
301
+
302
+ if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
303
+ typeof console.error === 'function') {
304
+ console.error(
305
+ 'This browser lacks typed array (Uint8Array) support which is required by ' +
306
+ '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
307
+ );
308
+ }
309
+
310
+ function typedArraySupport () {
311
+ // Can typed array instances can be augmented?
312
+ try {
313
+ const arr = new Uint8Array(1);
314
+ const proto = { foo: function () { return 42 } };
315
+ Object.setPrototypeOf(proto, Uint8Array.prototype);
316
+ Object.setPrototypeOf(arr, proto);
317
+ return arr.foo() === 42
318
+ } catch (e) {
319
+ return false
320
+ }
321
+ }
322
+
323
+ Object.defineProperty(Buffer.prototype, 'parent', {
324
+ enumerable: true,
325
+ get: function () {
326
+ if (!Buffer.isBuffer(this)) return undefined
327
+ return this.buffer
328
+ }
329
+ });
330
+
331
+ Object.defineProperty(Buffer.prototype, 'offset', {
332
+ enumerable: true,
333
+ get: function () {
334
+ if (!Buffer.isBuffer(this)) return undefined
335
+ return this.byteOffset
336
+ }
337
+ });
338
+
339
+ function createBuffer (length) {
340
+ if (length > K_MAX_LENGTH) {
341
+ throw new RangeError('The value "' + length + '" is invalid for option "size"')
342
+ }
343
+ // Return an augmented `Uint8Array` instance
344
+ const buf = new Uint8Array(length);
345
+ Object.setPrototypeOf(buf, Buffer.prototype);
346
+ return buf
347
+ }
348
+
349
+ /**
350
+ * The Buffer constructor returns instances of `Uint8Array` that have their
351
+ * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
352
+ * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
353
+ * and the `Uint8Array` methods. Square bracket notation works as expected -- it
354
+ * returns a single octet.
355
+ *
356
+ * The `Uint8Array` prototype remains unmodified.
357
+ */
358
+
359
+ function Buffer (arg, encodingOrOffset, length) {
360
+ // Common case.
361
+ if (typeof arg === 'number') {
362
+ if (typeof encodingOrOffset === 'string') {
363
+ throw new TypeError(
364
+ 'The "string" argument must be of type string. Received type number'
365
+ )
366
+ }
367
+ return allocUnsafe(arg)
368
+ }
369
+ return from(arg, encodingOrOffset, length)
370
+ }
371
+
372
+ Buffer.poolSize = 8192; // not used by this implementation
373
+
374
+ function from (value, encodingOrOffset, length) {
375
+ if (typeof value === 'string') {
376
+ return fromString(value, encodingOrOffset)
377
+ }
378
+
379
+ if (ArrayBuffer.isView(value)) {
380
+ return fromArrayView(value)
381
+ }
382
+
383
+ if (value == null) {
384
+ throw new TypeError(
385
+ 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
386
+ 'or Array-like Object. Received type ' + (typeof value)
387
+ )
388
+ }
389
+
390
+ if (isInstance(value, ArrayBuffer) ||
391
+ (value && isInstance(value.buffer, ArrayBuffer))) {
392
+ return fromArrayBuffer(value, encodingOrOffset, length)
393
+ }
394
+
395
+ if (typeof SharedArrayBuffer !== 'undefined' &&
396
+ (isInstance(value, SharedArrayBuffer) ||
397
+ (value && isInstance(value.buffer, SharedArrayBuffer)))) {
398
+ return fromArrayBuffer(value, encodingOrOffset, length)
399
+ }
400
+
401
+ if (typeof value === 'number') {
402
+ throw new TypeError(
403
+ 'The "value" argument must not be of type number. Received type number'
404
+ )
405
+ }
406
+
407
+ const valueOf = value.valueOf && value.valueOf();
408
+ if (valueOf != null && valueOf !== value) {
409
+ return Buffer.from(valueOf, encodingOrOffset, length)
410
+ }
411
+
412
+ const b = fromObject(value);
413
+ if (b) return b
414
+
415
+ if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
416
+ typeof value[Symbol.toPrimitive] === 'function') {
417
+ return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length)
418
+ }
419
+
420
+ throw new TypeError(
421
+ 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
422
+ 'or Array-like Object. Received type ' + (typeof value)
423
+ )
424
+ }
425
+
426
+ /**
427
+ * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
428
+ * if value is a number.
429
+ * Buffer.from(str[, encoding])
430
+ * Buffer.from(array)
431
+ * Buffer.from(buffer)
432
+ * Buffer.from(arrayBuffer[, byteOffset[, length]])
433
+ **/
434
+ Buffer.from = function (value, encodingOrOffset, length) {
435
+ return from(value, encodingOrOffset, length)
436
+ };
437
+
438
+ // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
439
+ // https://github.com/feross/buffer/pull/148
440
+ Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
441
+ Object.setPrototypeOf(Buffer, Uint8Array);
442
+
443
+ function assertSize (size) {
444
+ if (typeof size !== 'number') {
445
+ throw new TypeError('"size" argument must be of type number')
446
+ } else if (size < 0) {
447
+ throw new RangeError('The value "' + size + '" is invalid for option "size"')
448
+ }
449
+ }
450
+
451
+ function alloc (size, fill, encoding) {
452
+ assertSize(size);
453
+ if (size <= 0) {
454
+ return createBuffer(size)
455
+ }
456
+ if (fill !== undefined) {
457
+ // Only pay attention to encoding if it's a string. This
458
+ // prevents accidentally sending in a number that would
459
+ // be interpreted as a start offset.
460
+ return typeof encoding === 'string'
461
+ ? createBuffer(size).fill(fill, encoding)
462
+ : createBuffer(size).fill(fill)
463
+ }
464
+ return createBuffer(size)
465
+ }
466
+
467
+ /**
468
+ * Creates a new filled Buffer instance.
469
+ * alloc(size[, fill[, encoding]])
470
+ **/
471
+ Buffer.alloc = function (size, fill, encoding) {
472
+ return alloc(size, fill, encoding)
473
+ };
474
+
475
+ function allocUnsafe (size) {
476
+ assertSize(size);
477
+ return createBuffer(size < 0 ? 0 : checked(size) | 0)
478
+ }
479
+
480
+ /**
481
+ * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
482
+ * */
483
+ Buffer.allocUnsafe = function (size) {
484
+ return allocUnsafe(size)
485
+ };
486
+ /**
487
+ * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
488
+ */
489
+ Buffer.allocUnsafeSlow = function (size) {
490
+ return allocUnsafe(size)
491
+ };
492
+
493
+ function fromString (string, encoding) {
494
+ if (typeof encoding !== 'string' || encoding === '') {
495
+ encoding = 'utf8';
496
+ }
497
+
498
+ if (!Buffer.isEncoding(encoding)) {
499
+ throw new TypeError('Unknown encoding: ' + encoding)
500
+ }
501
+
502
+ const length = byteLength(string, encoding) | 0;
503
+ let buf = createBuffer(length);
504
+
505
+ const actual = buf.write(string, encoding);
506
+
507
+ if (actual !== length) {
508
+ // Writing a hex string, for example, that contains invalid characters will
509
+ // cause everything after the first invalid character to be ignored. (e.g.
510
+ // 'abxxcd' will be treated as 'ab')
511
+ buf = buf.slice(0, actual);
512
+ }
513
+
514
+ return buf
515
+ }
516
+
517
+ function fromArrayLike (array) {
518
+ const length = array.length < 0 ? 0 : checked(array.length) | 0;
519
+ const buf = createBuffer(length);
520
+ for (let i = 0; i < length; i += 1) {
521
+ buf[i] = array[i] & 255;
522
+ }
523
+ return buf
524
+ }
525
+
526
+ function fromArrayView (arrayView) {
527
+ if (isInstance(arrayView, Uint8Array)) {
528
+ const copy = new Uint8Array(arrayView);
529
+ return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)
530
+ }
531
+ return fromArrayLike(arrayView)
532
+ }
533
+
534
+ function fromArrayBuffer (array, byteOffset, length) {
535
+ if (byteOffset < 0 || array.byteLength < byteOffset) {
536
+ throw new RangeError('"offset" is outside of buffer bounds')
537
+ }
538
+
539
+ if (array.byteLength < byteOffset + (length || 0)) {
540
+ throw new RangeError('"length" is outside of buffer bounds')
541
+ }
542
+
543
+ let buf;
544
+ if (byteOffset === undefined && length === undefined) {
545
+ buf = new Uint8Array(array);
546
+ } else if (length === undefined) {
547
+ buf = new Uint8Array(array, byteOffset);
548
+ } else {
549
+ buf = new Uint8Array(array, byteOffset, length);
550
+ }
551
+
552
+ // Return an augmented `Uint8Array` instance
553
+ Object.setPrototypeOf(buf, Buffer.prototype);
554
+
555
+ return buf
556
+ }
557
+
558
+ function fromObject (obj) {
559
+ if (Buffer.isBuffer(obj)) {
560
+ const len = checked(obj.length) | 0;
561
+ const buf = createBuffer(len);
562
+
563
+ if (buf.length === 0) {
564
+ return buf
565
+ }
566
+
567
+ obj.copy(buf, 0, 0, len);
568
+ return buf
569
+ }
570
+
571
+ if (obj.length !== undefined) {
572
+ if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
573
+ return createBuffer(0)
574
+ }
575
+ return fromArrayLike(obj)
576
+ }
577
+
578
+ if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
579
+ return fromArrayLike(obj.data)
580
+ }
581
+ }
582
+
583
+ function checked (length) {
584
+ // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
585
+ // length is NaN (which is otherwise coerced to zero.)
586
+ if (length >= K_MAX_LENGTH) {
587
+ throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
588
+ 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
589
+ }
590
+ return length | 0
591
+ }
592
+
593
+ function SlowBuffer (length) {
594
+ if (+length != length) { // eslint-disable-line eqeqeq
595
+ length = 0;
596
+ }
597
+ return Buffer.alloc(+length)
598
+ }
599
+
600
+ Buffer.isBuffer = function isBuffer (b) {
601
+ return b != null && b._isBuffer === true &&
602
+ b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
603
+ };
604
+
605
+ Buffer.compare = function compare (a, b) {
606
+ if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);
607
+ if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);
608
+ if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
609
+ throw new TypeError(
610
+ 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
611
+ )
612
+ }
613
+
614
+ if (a === b) return 0
615
+
616
+ let x = a.length;
617
+ let y = b.length;
618
+
619
+ for (let i = 0, len = Math.min(x, y); i < len; ++i) {
620
+ if (a[i] !== b[i]) {
621
+ x = a[i];
622
+ y = b[i];
623
+ break
624
+ }
625
+ }
626
+
627
+ if (x < y) return -1
628
+ if (y < x) return 1
629
+ return 0
630
+ };
631
+
632
+ Buffer.isEncoding = function isEncoding (encoding) {
633
+ switch (String(encoding).toLowerCase()) {
634
+ case 'hex':
635
+ case 'utf8':
636
+ case 'utf-8':
637
+ case 'ascii':
638
+ case 'latin1':
639
+ case 'binary':
640
+ case 'base64':
641
+ case 'ucs2':
642
+ case 'ucs-2':
643
+ case 'utf16le':
644
+ case 'utf-16le':
645
+ return true
646
+ default:
647
+ return false
648
+ }
649
+ };
650
+
651
+ Buffer.concat = function concat (list, length) {
652
+ if (!Array.isArray(list)) {
653
+ throw new TypeError('"list" argument must be an Array of Buffers')
654
+ }
655
+
656
+ if (list.length === 0) {
657
+ return Buffer.alloc(0)
658
+ }
659
+
660
+ let i;
661
+ if (length === undefined) {
662
+ length = 0;
663
+ for (i = 0; i < list.length; ++i) {
664
+ length += list[i].length;
665
+ }
666
+ }
667
+
668
+ const buffer = Buffer.allocUnsafe(length);
669
+ let pos = 0;
670
+ for (i = 0; i < list.length; ++i) {
671
+ let buf = list[i];
672
+ if (isInstance(buf, Uint8Array)) {
673
+ if (pos + buf.length > buffer.length) {
674
+ if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf);
675
+ buf.copy(buffer, pos);
676
+ } else {
677
+ Uint8Array.prototype.set.call(
678
+ buffer,
679
+ buf,
680
+ pos
681
+ );
682
+ }
683
+ } else if (!Buffer.isBuffer(buf)) {
684
+ throw new TypeError('"list" argument must be an Array of Buffers')
685
+ } else {
686
+ buf.copy(buffer, pos);
687
+ }
688
+ pos += buf.length;
689
+ }
690
+ return buffer
691
+ };
692
+
693
+ function byteLength (string, encoding) {
694
+ if (Buffer.isBuffer(string)) {
695
+ return string.length
696
+ }
697
+ if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
698
+ return string.byteLength
699
+ }
700
+ if (typeof string !== 'string') {
701
+ throw new TypeError(
702
+ 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
703
+ 'Received type ' + typeof string
704
+ )
705
+ }
706
+
707
+ const len = string.length;
708
+ const mustMatch = (arguments.length > 2 && arguments[2] === true);
709
+ if (!mustMatch && len === 0) return 0
710
+
711
+ // Use a for loop to avoid recursion
712
+ let loweredCase = false;
713
+ for (;;) {
714
+ switch (encoding) {
715
+ case 'ascii':
716
+ case 'latin1':
717
+ case 'binary':
718
+ return len
719
+ case 'utf8':
720
+ case 'utf-8':
721
+ return utf8ToBytes(string).length
722
+ case 'ucs2':
723
+ case 'ucs-2':
724
+ case 'utf16le':
725
+ case 'utf-16le':
726
+ return len * 2
727
+ case 'hex':
728
+ return len >>> 1
729
+ case 'base64':
730
+ return base64ToBytes(string).length
731
+ default:
732
+ if (loweredCase) {
733
+ return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
734
+ }
735
+ encoding = ('' + encoding).toLowerCase();
736
+ loweredCase = true;
737
+ }
738
+ }
739
+ }
740
+ Buffer.byteLength = byteLength;
741
+
742
+ function slowToString (encoding, start, end) {
743
+ let loweredCase = false;
744
+
745
+ // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
746
+ // property of a typed array.
747
+
748
+ // This behaves neither like String nor Uint8Array in that we set start/end
749
+ // to their upper/lower bounds if the value passed is out of range.
750
+ // undefined is handled specially as per ECMA-262 6th Edition,
751
+ // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
752
+ if (start === undefined || start < 0) {
753
+ start = 0;
754
+ }
755
+ // Return early if start > this.length. Done here to prevent potential uint32
756
+ // coercion fail below.
757
+ if (start > this.length) {
758
+ return ''
759
+ }
760
+
761
+ if (end === undefined || end > this.length) {
762
+ end = this.length;
763
+ }
764
+
765
+ if (end <= 0) {
766
+ return ''
767
+ }
768
+
769
+ // Force coercion to uint32. This will also coerce falsey/NaN values to 0.
770
+ end >>>= 0;
771
+ start >>>= 0;
772
+
773
+ if (end <= start) {
774
+ return ''
775
+ }
776
+
777
+ if (!encoding) encoding = 'utf8';
778
+
779
+ while (true) {
780
+ switch (encoding) {
781
+ case 'hex':
782
+ return hexSlice(this, start, end)
783
+
784
+ case 'utf8':
785
+ case 'utf-8':
786
+ return utf8Slice(this, start, end)
787
+
788
+ case 'ascii':
789
+ return asciiSlice(this, start, end)
790
+
791
+ case 'latin1':
792
+ case 'binary':
793
+ return latin1Slice(this, start, end)
794
+
795
+ case 'base64':
796
+ return base64Slice(this, start, end)
797
+
798
+ case 'ucs2':
799
+ case 'ucs-2':
800
+ case 'utf16le':
801
+ case 'utf-16le':
802
+ return utf16leSlice(this, start, end)
803
+
804
+ default:
805
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
806
+ encoding = (encoding + '').toLowerCase();
807
+ loweredCase = true;
808
+ }
809
+ }
810
+ }
811
+
812
+ // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
813
+ // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
814
+ // reliably in a browserify context because there could be multiple different
815
+ // copies of the 'buffer' package in use. This method works even for Buffer
816
+ // instances that were created from another copy of the `buffer` package.
817
+ // See: https://github.com/feross/buffer/issues/154
818
+ Buffer.prototype._isBuffer = true;
819
+
820
+ function swap (b, n, m) {
821
+ const i = b[n];
822
+ b[n] = b[m];
823
+ b[m] = i;
824
+ }
825
+
826
+ Buffer.prototype.swap16 = function swap16 () {
827
+ const len = this.length;
828
+ if (len % 2 !== 0) {
829
+ throw new RangeError('Buffer size must be a multiple of 16-bits')
830
+ }
831
+ for (let i = 0; i < len; i += 2) {
832
+ swap(this, i, i + 1);
833
+ }
834
+ return this
835
+ };
836
+
837
+ Buffer.prototype.swap32 = function swap32 () {
838
+ const len = this.length;
839
+ if (len % 4 !== 0) {
840
+ throw new RangeError('Buffer size must be a multiple of 32-bits')
841
+ }
842
+ for (let i = 0; i < len; i += 4) {
843
+ swap(this, i, i + 3);
844
+ swap(this, i + 1, i + 2);
845
+ }
846
+ return this
847
+ };
848
+
849
+ Buffer.prototype.swap64 = function swap64 () {
850
+ const len = this.length;
851
+ if (len % 8 !== 0) {
852
+ throw new RangeError('Buffer size must be a multiple of 64-bits')
853
+ }
854
+ for (let i = 0; i < len; i += 8) {
855
+ swap(this, i, i + 7);
856
+ swap(this, i + 1, i + 6);
857
+ swap(this, i + 2, i + 5);
858
+ swap(this, i + 3, i + 4);
859
+ }
860
+ return this
861
+ };
862
+
863
+ Buffer.prototype.toString = function toString () {
864
+ const length = this.length;
865
+ if (length === 0) return ''
866
+ if (arguments.length === 0) return utf8Slice(this, 0, length)
867
+ return slowToString.apply(this, arguments)
868
+ };
869
+
870
+ Buffer.prototype.toLocaleString = Buffer.prototype.toString;
871
+
872
+ Buffer.prototype.equals = function equals (b) {
873
+ if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
874
+ if (this === b) return true
875
+ return Buffer.compare(this, b) === 0
876
+ };
877
+
878
+ Buffer.prototype.inspect = function inspect () {
879
+ let str = '';
880
+ const max = exports$1.INSPECT_MAX_BYTES;
881
+ str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
882
+ if (this.length > max) str += ' ... ';
883
+ return '<Buffer ' + str + '>'
884
+ };
885
+ if (customInspectSymbol) {
886
+ Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
887
+ }
888
+
889
+ Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
890
+ if (isInstance(target, Uint8Array)) {
891
+ target = Buffer.from(target, target.offset, target.byteLength);
892
+ }
893
+ if (!Buffer.isBuffer(target)) {
894
+ throw new TypeError(
895
+ 'The "target" argument must be one of type Buffer or Uint8Array. ' +
896
+ 'Received type ' + (typeof target)
897
+ )
898
+ }
899
+
900
+ if (start === undefined) {
901
+ start = 0;
902
+ }
903
+ if (end === undefined) {
904
+ end = target ? target.length : 0;
905
+ }
906
+ if (thisStart === undefined) {
907
+ thisStart = 0;
908
+ }
909
+ if (thisEnd === undefined) {
910
+ thisEnd = this.length;
911
+ }
912
+
913
+ if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
914
+ throw new RangeError('out of range index')
915
+ }
916
+
917
+ if (thisStart >= thisEnd && start >= end) {
918
+ return 0
919
+ }
920
+ if (thisStart >= thisEnd) {
921
+ return -1
922
+ }
923
+ if (start >= end) {
924
+ return 1
925
+ }
926
+
927
+ start >>>= 0;
928
+ end >>>= 0;
929
+ thisStart >>>= 0;
930
+ thisEnd >>>= 0;
931
+
932
+ if (this === target) return 0
933
+
934
+ let x = thisEnd - thisStart;
935
+ let y = end - start;
936
+ const len = Math.min(x, y);
937
+
938
+ const thisCopy = this.slice(thisStart, thisEnd);
939
+ const targetCopy = target.slice(start, end);
940
+
941
+ for (let i = 0; i < len; ++i) {
942
+ if (thisCopy[i] !== targetCopy[i]) {
943
+ x = thisCopy[i];
944
+ y = targetCopy[i];
945
+ break
946
+ }
947
+ }
948
+
949
+ if (x < y) return -1
950
+ if (y < x) return 1
951
+ return 0
952
+ };
953
+
954
+ // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
955
+ // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
956
+ //
957
+ // Arguments:
958
+ // - buffer - a Buffer to search
959
+ // - val - a string, Buffer, or number
960
+ // - byteOffset - an index into `buffer`; will be clamped to an int32
961
+ // - encoding - an optional encoding, relevant is val is a string
962
+ // - dir - true for indexOf, false for lastIndexOf
963
+ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
964
+ // Empty buffer means no match
965
+ if (buffer.length === 0) return -1
966
+
967
+ // Normalize byteOffset
968
+ if (typeof byteOffset === 'string') {
969
+ encoding = byteOffset;
970
+ byteOffset = 0;
971
+ } else if (byteOffset > 0x7fffffff) {
972
+ byteOffset = 0x7fffffff;
973
+ } else if (byteOffset < -2147483648) {
974
+ byteOffset = -2147483648;
975
+ }
976
+ byteOffset = +byteOffset; // Coerce to Number.
977
+ if (numberIsNaN(byteOffset)) {
978
+ // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
979
+ byteOffset = dir ? 0 : (buffer.length - 1);
980
+ }
981
+
982
+ // Normalize byteOffset: negative offsets start from the end of the buffer
983
+ if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
984
+ if (byteOffset >= buffer.length) {
985
+ if (dir) return -1
986
+ else byteOffset = buffer.length - 1;
987
+ } else if (byteOffset < 0) {
988
+ if (dir) byteOffset = 0;
989
+ else return -1
990
+ }
991
+
992
+ // Normalize val
993
+ if (typeof val === 'string') {
994
+ val = Buffer.from(val, encoding);
995
+ }
996
+
997
+ // Finally, search either indexOf (if dir is true) or lastIndexOf
998
+ if (Buffer.isBuffer(val)) {
999
+ // Special case: looking for empty string/buffer always fails
1000
+ if (val.length === 0) {
1001
+ return -1
1002
+ }
1003
+ return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
1004
+ } else if (typeof val === 'number') {
1005
+ val = val & 0xFF; // Search for a byte value [0-255]
1006
+ if (typeof Uint8Array.prototype.indexOf === 'function') {
1007
+ if (dir) {
1008
+ return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
1009
+ } else {
1010
+ return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
1011
+ }
1012
+ }
1013
+ return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
1014
+ }
1015
+
1016
+ throw new TypeError('val must be string, number or Buffer')
1017
+ }
1018
+
1019
+ function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
1020
+ let indexSize = 1;
1021
+ let arrLength = arr.length;
1022
+ let valLength = val.length;
1023
+
1024
+ if (encoding !== undefined) {
1025
+ encoding = String(encoding).toLowerCase();
1026
+ if (encoding === 'ucs2' || encoding === 'ucs-2' ||
1027
+ encoding === 'utf16le' || encoding === 'utf-16le') {
1028
+ if (arr.length < 2 || val.length < 2) {
1029
+ return -1
1030
+ }
1031
+ indexSize = 2;
1032
+ arrLength /= 2;
1033
+ valLength /= 2;
1034
+ byteOffset /= 2;
1035
+ }
1036
+ }
1037
+
1038
+ function read (buf, i) {
1039
+ if (indexSize === 1) {
1040
+ return buf[i]
1041
+ } else {
1042
+ return buf.readUInt16BE(i * indexSize)
1043
+ }
1044
+ }
1045
+
1046
+ let i;
1047
+ if (dir) {
1048
+ let foundIndex = -1;
1049
+ for (i = byteOffset; i < arrLength; i++) {
1050
+ if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
1051
+ if (foundIndex === -1) foundIndex = i;
1052
+ if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
1053
+ } else {
1054
+ if (foundIndex !== -1) i -= i - foundIndex;
1055
+ foundIndex = -1;
1056
+ }
1057
+ }
1058
+ } else {
1059
+ if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
1060
+ for (i = byteOffset; i >= 0; i--) {
1061
+ let found = true;
1062
+ for (let j = 0; j < valLength; j++) {
1063
+ if (read(arr, i + j) !== read(val, j)) {
1064
+ found = false;
1065
+ break
1066
+ }
1067
+ }
1068
+ if (found) return i
1069
+ }
1070
+ }
1071
+
1072
+ return -1
1073
+ }
1074
+
1075
+ Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
1076
+ return this.indexOf(val, byteOffset, encoding) !== -1
1077
+ };
1078
+
1079
+ Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
1080
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
1081
+ };
1082
+
1083
+ Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
1084
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
1085
+ };
1086
+
1087
+ function hexWrite (buf, string, offset, length) {
1088
+ offset = Number(offset) || 0;
1089
+ const remaining = buf.length - offset;
1090
+ if (!length) {
1091
+ length = remaining;
1092
+ } else {
1093
+ length = Number(length);
1094
+ if (length > remaining) {
1095
+ length = remaining;
1096
+ }
1097
+ }
1098
+
1099
+ const strLen = string.length;
1100
+
1101
+ if (length > strLen / 2) {
1102
+ length = strLen / 2;
1103
+ }
1104
+ let i;
1105
+ for (i = 0; i < length; ++i) {
1106
+ const parsed = parseInt(string.substr(i * 2, 2), 16);
1107
+ if (numberIsNaN(parsed)) return i
1108
+ buf[offset + i] = parsed;
1109
+ }
1110
+ return i
1111
+ }
1112
+
1113
+ function utf8Write (buf, string, offset, length) {
1114
+ return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
1115
+ }
1116
+
1117
+ function asciiWrite (buf, string, offset, length) {
1118
+ return blitBuffer(asciiToBytes(string), buf, offset, length)
1119
+ }
1120
+
1121
+ function base64Write (buf, string, offset, length) {
1122
+ return blitBuffer(base64ToBytes(string), buf, offset, length)
1123
+ }
1124
+
1125
+ function ucs2Write (buf, string, offset, length) {
1126
+ return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
1127
+ }
1128
+
1129
+ Buffer.prototype.write = function write (string, offset, length, encoding) {
1130
+ // Buffer#write(string)
1131
+ if (offset === undefined) {
1132
+ encoding = 'utf8';
1133
+ length = this.length;
1134
+ offset = 0;
1135
+ // Buffer#write(string, encoding)
1136
+ } else if (length === undefined && typeof offset === 'string') {
1137
+ encoding = offset;
1138
+ length = this.length;
1139
+ offset = 0;
1140
+ // Buffer#write(string, offset[, length][, encoding])
1141
+ } else if (isFinite(offset)) {
1142
+ offset = offset >>> 0;
1143
+ if (isFinite(length)) {
1144
+ length = length >>> 0;
1145
+ if (encoding === undefined) encoding = 'utf8';
1146
+ } else {
1147
+ encoding = length;
1148
+ length = undefined;
1149
+ }
1150
+ } else {
1151
+ throw new Error(
1152
+ 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
1153
+ )
1154
+ }
1155
+
1156
+ const remaining = this.length - offset;
1157
+ if (length === undefined || length > remaining) length = remaining;
1158
+
1159
+ if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
1160
+ throw new RangeError('Attempt to write outside buffer bounds')
1161
+ }
1162
+
1163
+ if (!encoding) encoding = 'utf8';
1164
+
1165
+ let loweredCase = false;
1166
+ for (;;) {
1167
+ switch (encoding) {
1168
+ case 'hex':
1169
+ return hexWrite(this, string, offset, length)
1170
+
1171
+ case 'utf8':
1172
+ case 'utf-8':
1173
+ return utf8Write(this, string, offset, length)
1174
+
1175
+ case 'ascii':
1176
+ case 'latin1':
1177
+ case 'binary':
1178
+ return asciiWrite(this, string, offset, length)
1179
+
1180
+ case 'base64':
1181
+ // Warning: maxLength not taken into account in base64Write
1182
+ return base64Write(this, string, offset, length)
1183
+
1184
+ case 'ucs2':
1185
+ case 'ucs-2':
1186
+ case 'utf16le':
1187
+ case 'utf-16le':
1188
+ return ucs2Write(this, string, offset, length)
1189
+
1190
+ default:
1191
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
1192
+ encoding = ('' + encoding).toLowerCase();
1193
+ loweredCase = true;
1194
+ }
1195
+ }
1196
+ };
1197
+
1198
+ Buffer.prototype.toJSON = function toJSON () {
1199
+ return {
1200
+ type: 'Buffer',
1201
+ data: Array.prototype.slice.call(this._arr || this, 0)
1202
+ }
1203
+ };
1204
+
1205
+ function base64Slice (buf, start, end) {
1206
+ if (start === 0 && end === buf.length) {
1207
+ return base64.fromByteArray(buf)
1208
+ } else {
1209
+ return base64.fromByteArray(buf.slice(start, end))
1210
+ }
1211
+ }
1212
+
1213
+ function utf8Slice (buf, start, end) {
1214
+ end = Math.min(buf.length, end);
1215
+ const res = [];
1216
+
1217
+ let i = start;
1218
+ while (i < end) {
1219
+ const firstByte = buf[i];
1220
+ let codePoint = null;
1221
+ let bytesPerSequence = (firstByte > 0xEF)
1222
+ ? 4
1223
+ : (firstByte > 0xDF)
1224
+ ? 3
1225
+ : (firstByte > 0xBF)
1226
+ ? 2
1227
+ : 1;
1228
+
1229
+ if (i + bytesPerSequence <= end) {
1230
+ let secondByte, thirdByte, fourthByte, tempCodePoint;
1231
+
1232
+ switch (bytesPerSequence) {
1233
+ case 1:
1234
+ if (firstByte < 0x80) {
1235
+ codePoint = firstByte;
1236
+ }
1237
+ break
1238
+ case 2:
1239
+ secondByte = buf[i + 1];
1240
+ if ((secondByte & 0xC0) === 0x80) {
1241
+ tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
1242
+ if (tempCodePoint > 0x7F) {
1243
+ codePoint = tempCodePoint;
1244
+ }
1245
+ }
1246
+ break
1247
+ case 3:
1248
+ secondByte = buf[i + 1];
1249
+ thirdByte = buf[i + 2];
1250
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
1251
+ tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
1252
+ if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
1253
+ codePoint = tempCodePoint;
1254
+ }
1255
+ }
1256
+ break
1257
+ case 4:
1258
+ secondByte = buf[i + 1];
1259
+ thirdByte = buf[i + 2];
1260
+ fourthByte = buf[i + 3];
1261
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
1262
+ tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
1263
+ if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
1264
+ codePoint = tempCodePoint;
1265
+ }
1266
+ }
1267
+ }
1268
+ }
1269
+
1270
+ if (codePoint === null) {
1271
+ // we did not generate a valid codePoint so insert a
1272
+ // replacement char (U+FFFD) and advance only 1 byte
1273
+ codePoint = 0xFFFD;
1274
+ bytesPerSequence = 1;
1275
+ } else if (codePoint > 0xFFFF) {
1276
+ // encode to utf16 (surrogate pair dance)
1277
+ codePoint -= 0x10000;
1278
+ res.push(codePoint >>> 10 & 0x3FF | 0xD800);
1279
+ codePoint = 0xDC00 | codePoint & 0x3FF;
1280
+ }
1281
+
1282
+ res.push(codePoint);
1283
+ i += bytesPerSequence;
1284
+ }
1285
+
1286
+ return decodeCodePointsArray(res)
1287
+ }
1288
+
1289
+ // Based on http://stackoverflow.com/a/22747272/680742, the browser with
1290
+ // the lowest limit is Chrome, with 0x10000 args.
1291
+ // We go 1 magnitude less, for safety
1292
+ const MAX_ARGUMENTS_LENGTH = 0x1000;
1293
+
1294
+ function decodeCodePointsArray (codePoints) {
1295
+ const len = codePoints.length;
1296
+ if (len <= MAX_ARGUMENTS_LENGTH) {
1297
+ return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
1298
+ }
1299
+
1300
+ // Decode in chunks to avoid "call stack size exceeded".
1301
+ let res = '';
1302
+ let i = 0;
1303
+ while (i < len) {
1304
+ res += String.fromCharCode.apply(
1305
+ String,
1306
+ codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
1307
+ );
1308
+ }
1309
+ return res
1310
+ }
1311
+
1312
+ function asciiSlice (buf, start, end) {
1313
+ let ret = '';
1314
+ end = Math.min(buf.length, end);
1315
+
1316
+ for (let i = start; i < end; ++i) {
1317
+ ret += String.fromCharCode(buf[i] & 0x7F);
1318
+ }
1319
+ return ret
1320
+ }
1321
+
1322
+ function latin1Slice (buf, start, end) {
1323
+ let ret = '';
1324
+ end = Math.min(buf.length, end);
1325
+
1326
+ for (let i = start; i < end; ++i) {
1327
+ ret += String.fromCharCode(buf[i]);
1328
+ }
1329
+ return ret
1330
+ }
1331
+
1332
+ function hexSlice (buf, start, end) {
1333
+ const len = buf.length;
1334
+
1335
+ if (!start || start < 0) start = 0;
1336
+ if (!end || end < 0 || end > len) end = len;
1337
+
1338
+ let out = '';
1339
+ for (let i = start; i < end; ++i) {
1340
+ out += hexSliceLookupTable[buf[i]];
1341
+ }
1342
+ return out
1343
+ }
1344
+
1345
+ function utf16leSlice (buf, start, end) {
1346
+ const bytes = buf.slice(start, end);
1347
+ let res = '';
1348
+ // If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
1349
+ for (let i = 0; i < bytes.length - 1; i += 2) {
1350
+ res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256));
1351
+ }
1352
+ return res
1353
+ }
1354
+
1355
+ Buffer.prototype.slice = function slice (start, end) {
1356
+ const len = this.length;
1357
+ start = ~~start;
1358
+ end = end === undefined ? len : ~~end;
1359
+
1360
+ if (start < 0) {
1361
+ start += len;
1362
+ if (start < 0) start = 0;
1363
+ } else if (start > len) {
1364
+ start = len;
1365
+ }
1366
+
1367
+ if (end < 0) {
1368
+ end += len;
1369
+ if (end < 0) end = 0;
1370
+ } else if (end > len) {
1371
+ end = len;
1372
+ }
1373
+
1374
+ if (end < start) end = start;
1375
+
1376
+ const newBuf = this.subarray(start, end);
1377
+ // Return an augmented `Uint8Array` instance
1378
+ Object.setPrototypeOf(newBuf, Buffer.prototype);
1379
+
1380
+ return newBuf
1381
+ };
1382
+
1383
+ /*
1384
+ * Need to make sure that buffer isn't trying to write out of bounds.
1385
+ */
1386
+ function checkOffset (offset, ext, length) {
1387
+ if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
1388
+ if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
1389
+ }
1390
+
1391
+ Buffer.prototype.readUintLE =
1392
+ Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
1393
+ offset = offset >>> 0;
1394
+ byteLength = byteLength >>> 0;
1395
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
1396
+
1397
+ let val = this[offset];
1398
+ let mul = 1;
1399
+ let i = 0;
1400
+ while (++i < byteLength && (mul *= 0x100)) {
1401
+ val += this[offset + i] * mul;
1402
+ }
1403
+
1404
+ return val
1405
+ };
1406
+
1407
+ Buffer.prototype.readUintBE =
1408
+ Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
1409
+ offset = offset >>> 0;
1410
+ byteLength = byteLength >>> 0;
1411
+ if (!noAssert) {
1412
+ checkOffset(offset, byteLength, this.length);
1413
+ }
1414
+
1415
+ let val = this[offset + --byteLength];
1416
+ let mul = 1;
1417
+ while (byteLength > 0 && (mul *= 0x100)) {
1418
+ val += this[offset + --byteLength] * mul;
1419
+ }
1420
+
1421
+ return val
1422
+ };
1423
+
1424
+ Buffer.prototype.readUint8 =
1425
+ Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
1426
+ offset = offset >>> 0;
1427
+ if (!noAssert) checkOffset(offset, 1, this.length);
1428
+ return this[offset]
1429
+ };
1430
+
1431
+ Buffer.prototype.readUint16LE =
1432
+ Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
1433
+ offset = offset >>> 0;
1434
+ if (!noAssert) checkOffset(offset, 2, this.length);
1435
+ return this[offset] | (this[offset + 1] << 8)
1436
+ };
1437
+
1438
+ Buffer.prototype.readUint16BE =
1439
+ Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
1440
+ offset = offset >>> 0;
1441
+ if (!noAssert) checkOffset(offset, 2, this.length);
1442
+ return (this[offset] << 8) | this[offset + 1]
1443
+ };
1444
+
1445
+ Buffer.prototype.readUint32LE =
1446
+ Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
1447
+ offset = offset >>> 0;
1448
+ if (!noAssert) checkOffset(offset, 4, this.length);
1449
+
1450
+ return ((this[offset]) |
1451
+ (this[offset + 1] << 8) |
1452
+ (this[offset + 2] << 16)) +
1453
+ (this[offset + 3] * 0x1000000)
1454
+ };
1455
+
1456
+ Buffer.prototype.readUint32BE =
1457
+ Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
1458
+ offset = offset >>> 0;
1459
+ if (!noAssert) checkOffset(offset, 4, this.length);
1460
+
1461
+ return (this[offset] * 0x1000000) +
1462
+ ((this[offset + 1] << 16) |
1463
+ (this[offset + 2] << 8) |
1464
+ this[offset + 3])
1465
+ };
1466
+
1467
+ Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE (offset) {
1468
+ offset = offset >>> 0;
1469
+ validateNumber(offset, 'offset');
1470
+ const first = this[offset];
1471
+ const last = this[offset + 7];
1472
+ if (first === undefined || last === undefined) {
1473
+ boundsError(offset, this.length - 8);
1474
+ }
1475
+
1476
+ const lo = first +
1477
+ this[++offset] * 2 ** 8 +
1478
+ this[++offset] * 2 ** 16 +
1479
+ this[++offset] * 2 ** 24;
1480
+
1481
+ const hi = this[++offset] +
1482
+ this[++offset] * 2 ** 8 +
1483
+ this[++offset] * 2 ** 16 +
1484
+ last * 2 ** 24;
1485
+
1486
+ return BigInt(lo) + (BigInt(hi) << BigInt(32))
1487
+ });
1488
+
1489
+ Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE (offset) {
1490
+ offset = offset >>> 0;
1491
+ validateNumber(offset, 'offset');
1492
+ const first = this[offset];
1493
+ const last = this[offset + 7];
1494
+ if (first === undefined || last === undefined) {
1495
+ boundsError(offset, this.length - 8);
1496
+ }
1497
+
1498
+ const hi = first * 2 ** 24 +
1499
+ this[++offset] * 2 ** 16 +
1500
+ this[++offset] * 2 ** 8 +
1501
+ this[++offset];
1502
+
1503
+ const lo = this[++offset] * 2 ** 24 +
1504
+ this[++offset] * 2 ** 16 +
1505
+ this[++offset] * 2 ** 8 +
1506
+ last;
1507
+
1508
+ return (BigInt(hi) << BigInt(32)) + BigInt(lo)
1509
+ });
1510
+
1511
+ Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
1512
+ offset = offset >>> 0;
1513
+ byteLength = byteLength >>> 0;
1514
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
1515
+
1516
+ let val = this[offset];
1517
+ let mul = 1;
1518
+ let i = 0;
1519
+ while (++i < byteLength && (mul *= 0x100)) {
1520
+ val += this[offset + i] * mul;
1521
+ }
1522
+ mul *= 0x80;
1523
+
1524
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength);
1525
+
1526
+ return val
1527
+ };
1528
+
1529
+ Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
1530
+ offset = offset >>> 0;
1531
+ byteLength = byteLength >>> 0;
1532
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
1533
+
1534
+ let i = byteLength;
1535
+ let mul = 1;
1536
+ let val = this[offset + --i];
1537
+ while (i > 0 && (mul *= 0x100)) {
1538
+ val += this[offset + --i] * mul;
1539
+ }
1540
+ mul *= 0x80;
1541
+
1542
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength);
1543
+
1544
+ return val
1545
+ };
1546
+
1547
+ Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
1548
+ offset = offset >>> 0;
1549
+ if (!noAssert) checkOffset(offset, 1, this.length);
1550
+ if (!(this[offset] & 0x80)) return (this[offset])
1551
+ return ((0xff - this[offset] + 1) * -1)
1552
+ };
1553
+
1554
+ Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
1555
+ offset = offset >>> 0;
1556
+ if (!noAssert) checkOffset(offset, 2, this.length);
1557
+ const val = this[offset] | (this[offset + 1] << 8);
1558
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
1559
+ };
1560
+
1561
+ Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
1562
+ offset = offset >>> 0;
1563
+ if (!noAssert) checkOffset(offset, 2, this.length);
1564
+ const val = this[offset + 1] | (this[offset] << 8);
1565
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
1566
+ };
1567
+
1568
+ Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
1569
+ offset = offset >>> 0;
1570
+ if (!noAssert) checkOffset(offset, 4, this.length);
1571
+
1572
+ return (this[offset]) |
1573
+ (this[offset + 1] << 8) |
1574
+ (this[offset + 2] << 16) |
1575
+ (this[offset + 3] << 24)
1576
+ };
1577
+
1578
+ Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
1579
+ offset = offset >>> 0;
1580
+ if (!noAssert) checkOffset(offset, 4, this.length);
1581
+
1582
+ return (this[offset] << 24) |
1583
+ (this[offset + 1] << 16) |
1584
+ (this[offset + 2] << 8) |
1585
+ (this[offset + 3])
1586
+ };
1587
+
1588
+ Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE (offset) {
1589
+ offset = offset >>> 0;
1590
+ validateNumber(offset, 'offset');
1591
+ const first = this[offset];
1592
+ const last = this[offset + 7];
1593
+ if (first === undefined || last === undefined) {
1594
+ boundsError(offset, this.length - 8);
1595
+ }
1596
+
1597
+ const val = this[offset + 4] +
1598
+ this[offset + 5] * 2 ** 8 +
1599
+ this[offset + 6] * 2 ** 16 +
1600
+ (last << 24); // Overflow
1601
+
1602
+ return (BigInt(val) << BigInt(32)) +
1603
+ BigInt(first +
1604
+ this[++offset] * 2 ** 8 +
1605
+ this[++offset] * 2 ** 16 +
1606
+ this[++offset] * 2 ** 24)
1607
+ });
1608
+
1609
+ Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE (offset) {
1610
+ offset = offset >>> 0;
1611
+ validateNumber(offset, 'offset');
1612
+ const first = this[offset];
1613
+ const last = this[offset + 7];
1614
+ if (first === undefined || last === undefined) {
1615
+ boundsError(offset, this.length - 8);
1616
+ }
1617
+
1618
+ const val = (first << 24) + // Overflow
1619
+ this[++offset] * 2 ** 16 +
1620
+ this[++offset] * 2 ** 8 +
1621
+ this[++offset];
1622
+
1623
+ return (BigInt(val) << BigInt(32)) +
1624
+ BigInt(this[++offset] * 2 ** 24 +
1625
+ this[++offset] * 2 ** 16 +
1626
+ this[++offset] * 2 ** 8 +
1627
+ last)
1628
+ });
1629
+
1630
+ Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
1631
+ offset = offset >>> 0;
1632
+ if (!noAssert) checkOffset(offset, 4, this.length);
1633
+ return ieee754.read(this, offset, true, 23, 4)
1634
+ };
1635
+
1636
+ Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
1637
+ offset = offset >>> 0;
1638
+ if (!noAssert) checkOffset(offset, 4, this.length);
1639
+ return ieee754.read(this, offset, false, 23, 4)
1640
+ };
1641
+
1642
+ Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
1643
+ offset = offset >>> 0;
1644
+ if (!noAssert) checkOffset(offset, 8, this.length);
1645
+ return ieee754.read(this, offset, true, 52, 8)
1646
+ };
1647
+
1648
+ Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
1649
+ offset = offset >>> 0;
1650
+ if (!noAssert) checkOffset(offset, 8, this.length);
1651
+ return ieee754.read(this, offset, false, 52, 8)
1652
+ };
1653
+
1654
+ function checkInt (buf, value, offset, ext, max, min) {
1655
+ if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
1656
+ if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
1657
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
1658
+ }
1659
+
1660
+ Buffer.prototype.writeUintLE =
1661
+ Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
1662
+ value = +value;
1663
+ offset = offset >>> 0;
1664
+ byteLength = byteLength >>> 0;
1665
+ if (!noAssert) {
1666
+ const maxBytes = Math.pow(2, 8 * byteLength) - 1;
1667
+ checkInt(this, value, offset, byteLength, maxBytes, 0);
1668
+ }
1669
+
1670
+ let mul = 1;
1671
+ let i = 0;
1672
+ this[offset] = value & 0xFF;
1673
+ while (++i < byteLength && (mul *= 0x100)) {
1674
+ this[offset + i] = (value / mul) & 0xFF;
1675
+ }
1676
+
1677
+ return offset + byteLength
1678
+ };
1679
+
1680
+ Buffer.prototype.writeUintBE =
1681
+ Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
1682
+ value = +value;
1683
+ offset = offset >>> 0;
1684
+ byteLength = byteLength >>> 0;
1685
+ if (!noAssert) {
1686
+ const maxBytes = Math.pow(2, 8 * byteLength) - 1;
1687
+ checkInt(this, value, offset, byteLength, maxBytes, 0);
1688
+ }
1689
+
1690
+ let i = byteLength - 1;
1691
+ let mul = 1;
1692
+ this[offset + i] = value & 0xFF;
1693
+ while (--i >= 0 && (mul *= 0x100)) {
1694
+ this[offset + i] = (value / mul) & 0xFF;
1695
+ }
1696
+
1697
+ return offset + byteLength
1698
+ };
1699
+
1700
+ Buffer.prototype.writeUint8 =
1701
+ Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
1702
+ value = +value;
1703
+ offset = offset >>> 0;
1704
+ if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
1705
+ this[offset] = (value & 0xff);
1706
+ return offset + 1
1707
+ };
1708
+
1709
+ Buffer.prototype.writeUint16LE =
1710
+ Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
1711
+ value = +value;
1712
+ offset = offset >>> 0;
1713
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
1714
+ this[offset] = (value & 0xff);
1715
+ this[offset + 1] = (value >>> 8);
1716
+ return offset + 2
1717
+ };
1718
+
1719
+ Buffer.prototype.writeUint16BE =
1720
+ Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
1721
+ value = +value;
1722
+ offset = offset >>> 0;
1723
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
1724
+ this[offset] = (value >>> 8);
1725
+ this[offset + 1] = (value & 0xff);
1726
+ return offset + 2
1727
+ };
1728
+
1729
+ Buffer.prototype.writeUint32LE =
1730
+ Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
1731
+ value = +value;
1732
+ offset = offset >>> 0;
1733
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
1734
+ this[offset + 3] = (value >>> 24);
1735
+ this[offset + 2] = (value >>> 16);
1736
+ this[offset + 1] = (value >>> 8);
1737
+ this[offset] = (value & 0xff);
1738
+ return offset + 4
1739
+ };
1740
+
1741
+ Buffer.prototype.writeUint32BE =
1742
+ Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
1743
+ value = +value;
1744
+ offset = offset >>> 0;
1745
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
1746
+ this[offset] = (value >>> 24);
1747
+ this[offset + 1] = (value >>> 16);
1748
+ this[offset + 2] = (value >>> 8);
1749
+ this[offset + 3] = (value & 0xff);
1750
+ return offset + 4
1751
+ };
1752
+
1753
+ function wrtBigUInt64LE (buf, value, offset, min, max) {
1754
+ checkIntBI(value, min, max, buf, offset, 7);
1755
+
1756
+ let lo = Number(value & BigInt(0xffffffff));
1757
+ buf[offset++] = lo;
1758
+ lo = lo >> 8;
1759
+ buf[offset++] = lo;
1760
+ lo = lo >> 8;
1761
+ buf[offset++] = lo;
1762
+ lo = lo >> 8;
1763
+ buf[offset++] = lo;
1764
+ let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
1765
+ buf[offset++] = hi;
1766
+ hi = hi >> 8;
1767
+ buf[offset++] = hi;
1768
+ hi = hi >> 8;
1769
+ buf[offset++] = hi;
1770
+ hi = hi >> 8;
1771
+ buf[offset++] = hi;
1772
+ return offset
1773
+ }
1774
+
1775
+ function wrtBigUInt64BE (buf, value, offset, min, max) {
1776
+ checkIntBI(value, min, max, buf, offset, 7);
1777
+
1778
+ let lo = Number(value & BigInt(0xffffffff));
1779
+ buf[offset + 7] = lo;
1780
+ lo = lo >> 8;
1781
+ buf[offset + 6] = lo;
1782
+ lo = lo >> 8;
1783
+ buf[offset + 5] = lo;
1784
+ lo = lo >> 8;
1785
+ buf[offset + 4] = lo;
1786
+ let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
1787
+ buf[offset + 3] = hi;
1788
+ hi = hi >> 8;
1789
+ buf[offset + 2] = hi;
1790
+ hi = hi >> 8;
1791
+ buf[offset + 1] = hi;
1792
+ hi = hi >> 8;
1793
+ buf[offset] = hi;
1794
+ return offset + 8
1795
+ }
1796
+
1797
+ Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE (value, offset = 0) {
1798
+ return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
1799
+ });
1800
+
1801
+ Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE (value, offset = 0) {
1802
+ return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
1803
+ });
1804
+
1805
+ Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
1806
+ value = +value;
1807
+ offset = offset >>> 0;
1808
+ if (!noAssert) {
1809
+ const limit = Math.pow(2, (8 * byteLength) - 1);
1810
+
1811
+ checkInt(this, value, offset, byteLength, limit - 1, -limit);
1812
+ }
1813
+
1814
+ let i = 0;
1815
+ let mul = 1;
1816
+ let sub = 0;
1817
+ this[offset] = value & 0xFF;
1818
+ while (++i < byteLength && (mul *= 0x100)) {
1819
+ if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
1820
+ sub = 1;
1821
+ }
1822
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
1823
+ }
1824
+
1825
+ return offset + byteLength
1826
+ };
1827
+
1828
+ Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
1829
+ value = +value;
1830
+ offset = offset >>> 0;
1831
+ if (!noAssert) {
1832
+ const limit = Math.pow(2, (8 * byteLength) - 1);
1833
+
1834
+ checkInt(this, value, offset, byteLength, limit - 1, -limit);
1835
+ }
1836
+
1837
+ let i = byteLength - 1;
1838
+ let mul = 1;
1839
+ let sub = 0;
1840
+ this[offset + i] = value & 0xFF;
1841
+ while (--i >= 0 && (mul *= 0x100)) {
1842
+ if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
1843
+ sub = 1;
1844
+ }
1845
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
1846
+ }
1847
+
1848
+ return offset + byteLength
1849
+ };
1850
+
1851
+ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
1852
+ value = +value;
1853
+ offset = offset >>> 0;
1854
+ if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
1855
+ if (value < 0) value = 0xff + value + 1;
1856
+ this[offset] = (value & 0xff);
1857
+ return offset + 1
1858
+ };
1859
+
1860
+ Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
1861
+ value = +value;
1862
+ offset = offset >>> 0;
1863
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
1864
+ this[offset] = (value & 0xff);
1865
+ this[offset + 1] = (value >>> 8);
1866
+ return offset + 2
1867
+ };
1868
+
1869
+ Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
1870
+ value = +value;
1871
+ offset = offset >>> 0;
1872
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
1873
+ this[offset] = (value >>> 8);
1874
+ this[offset + 1] = (value & 0xff);
1875
+ return offset + 2
1876
+ };
1877
+
1878
+ Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
1879
+ value = +value;
1880
+ offset = offset >>> 0;
1881
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
1882
+ this[offset] = (value & 0xff);
1883
+ this[offset + 1] = (value >>> 8);
1884
+ this[offset + 2] = (value >>> 16);
1885
+ this[offset + 3] = (value >>> 24);
1886
+ return offset + 4
1887
+ };
1888
+
1889
+ Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
1890
+ value = +value;
1891
+ offset = offset >>> 0;
1892
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
1893
+ if (value < 0) value = 0xffffffff + value + 1;
1894
+ this[offset] = (value >>> 24);
1895
+ this[offset + 1] = (value >>> 16);
1896
+ this[offset + 2] = (value >>> 8);
1897
+ this[offset + 3] = (value & 0xff);
1898
+ return offset + 4
1899
+ };
1900
+
1901
+ Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE (value, offset = 0) {
1902
+ return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
1903
+ });
1904
+
1905
+ Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE (value, offset = 0) {
1906
+ return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
1907
+ });
1908
+
1909
+ function checkIEEE754 (buf, value, offset, ext, max, min) {
1910
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
1911
+ if (offset < 0) throw new RangeError('Index out of range')
1912
+ }
1913
+
1914
+ function writeFloat (buf, value, offset, littleEndian, noAssert) {
1915
+ value = +value;
1916
+ offset = offset >>> 0;
1917
+ if (!noAssert) {
1918
+ checkIEEE754(buf, value, offset, 4);
1919
+ }
1920
+ ieee754.write(buf, value, offset, littleEndian, 23, 4);
1921
+ return offset + 4
1922
+ }
1923
+
1924
+ Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
1925
+ return writeFloat(this, value, offset, true, noAssert)
1926
+ };
1927
+
1928
+ Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
1929
+ return writeFloat(this, value, offset, false, noAssert)
1930
+ };
1931
+
1932
+ function writeDouble (buf, value, offset, littleEndian, noAssert) {
1933
+ value = +value;
1934
+ offset = offset >>> 0;
1935
+ if (!noAssert) {
1936
+ checkIEEE754(buf, value, offset, 8);
1937
+ }
1938
+ ieee754.write(buf, value, offset, littleEndian, 52, 8);
1939
+ return offset + 8
1940
+ }
1941
+
1942
+ Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
1943
+ return writeDouble(this, value, offset, true, noAssert)
1944
+ };
1945
+
1946
+ Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
1947
+ return writeDouble(this, value, offset, false, noAssert)
1948
+ };
1949
+
1950
+ // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
1951
+ Buffer.prototype.copy = function copy (target, targetStart, start, end) {
1952
+ if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
1953
+ if (!start) start = 0;
1954
+ if (!end && end !== 0) end = this.length;
1955
+ if (targetStart >= target.length) targetStart = target.length;
1956
+ if (!targetStart) targetStart = 0;
1957
+ if (end > 0 && end < start) end = start;
1958
+
1959
+ // Copy 0 bytes; we're done
1960
+ if (end === start) return 0
1961
+ if (target.length === 0 || this.length === 0) return 0
1962
+
1963
+ // Fatal error conditions
1964
+ if (targetStart < 0) {
1965
+ throw new RangeError('targetStart out of bounds')
1966
+ }
1967
+ if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
1968
+ if (end < 0) throw new RangeError('sourceEnd out of bounds')
1969
+
1970
+ // Are we oob?
1971
+ if (end > this.length) end = this.length;
1972
+ if (target.length - targetStart < end - start) {
1973
+ end = target.length - targetStart + start;
1974
+ }
1975
+
1976
+ const len = end - start;
1977
+
1978
+ if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
1979
+ // Use built-in when available, missing from IE11
1980
+ this.copyWithin(targetStart, start, end);
1981
+ } else {
1982
+ Uint8Array.prototype.set.call(
1983
+ target,
1984
+ this.subarray(start, end),
1985
+ targetStart
1986
+ );
1987
+ }
1988
+
1989
+ return len
1990
+ };
1991
+
1992
+ // Usage:
1993
+ // buffer.fill(number[, offset[, end]])
1994
+ // buffer.fill(buffer[, offset[, end]])
1995
+ // buffer.fill(string[, offset[, end]][, encoding])
1996
+ Buffer.prototype.fill = function fill (val, start, end, encoding) {
1997
+ // Handle string cases:
1998
+ if (typeof val === 'string') {
1999
+ if (typeof start === 'string') {
2000
+ encoding = start;
2001
+ start = 0;
2002
+ end = this.length;
2003
+ } else if (typeof end === 'string') {
2004
+ encoding = end;
2005
+ end = this.length;
2006
+ }
2007
+ if (encoding !== undefined && typeof encoding !== 'string') {
2008
+ throw new TypeError('encoding must be a string')
2009
+ }
2010
+ if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
2011
+ throw new TypeError('Unknown encoding: ' + encoding)
2012
+ }
2013
+ if (val.length === 1) {
2014
+ const code = val.charCodeAt(0);
2015
+ if ((encoding === 'utf8' && code < 128) ||
2016
+ encoding === 'latin1') {
2017
+ // Fast path: If `val` fits into a single byte, use that numeric value.
2018
+ val = code;
2019
+ }
2020
+ }
2021
+ } else if (typeof val === 'number') {
2022
+ val = val & 255;
2023
+ } else if (typeof val === 'boolean') {
2024
+ val = Number(val);
2025
+ }
2026
+
2027
+ // Invalid ranges are not set to a default, so can range check early.
2028
+ if (start < 0 || this.length < start || this.length < end) {
2029
+ throw new RangeError('Out of range index')
2030
+ }
2031
+
2032
+ if (end <= start) {
2033
+ return this
2034
+ }
2035
+
2036
+ start = start >>> 0;
2037
+ end = end === undefined ? this.length : end >>> 0;
2038
+
2039
+ if (!val) val = 0;
2040
+
2041
+ let i;
2042
+ if (typeof val === 'number') {
2043
+ for (i = start; i < end; ++i) {
2044
+ this[i] = val;
2045
+ }
2046
+ } else {
2047
+ const bytes = Buffer.isBuffer(val)
2048
+ ? val
2049
+ : Buffer.from(val, encoding);
2050
+ const len = bytes.length;
2051
+ if (len === 0) {
2052
+ throw new TypeError('The value "' + val +
2053
+ '" is invalid for argument "value"')
2054
+ }
2055
+ for (i = 0; i < end - start; ++i) {
2056
+ this[i + start] = bytes[i % len];
2057
+ }
2058
+ }
2059
+
2060
+ return this
2061
+ };
2062
+
2063
+ // CUSTOM ERRORS
2064
+ // =============
2065
+
2066
+ // Simplified versions from Node, changed for Buffer-only usage
2067
+ const errors = {};
2068
+ function E (sym, getMessage, Base) {
2069
+ errors[sym] = class NodeError extends Base {
2070
+ constructor () {
2071
+ super();
2072
+
2073
+ Object.defineProperty(this, 'message', {
2074
+ value: getMessage.apply(this, arguments),
2075
+ writable: true,
2076
+ configurable: true
2077
+ });
2078
+
2079
+ // Add the error code to the name to include it in the stack trace.
2080
+ this.name = `${this.name} [${sym}]`;
2081
+ // Access the stack to generate the error message including the error code
2082
+ // from the name.
2083
+ this.stack; // eslint-disable-line no-unused-expressions
2084
+ // Reset the name to the actual name.
2085
+ delete this.name;
2086
+ }
2087
+
2088
+ get code () {
2089
+ return sym
2090
+ }
2091
+
2092
+ set code (value) {
2093
+ Object.defineProperty(this, 'code', {
2094
+ configurable: true,
2095
+ enumerable: true,
2096
+ value,
2097
+ writable: true
2098
+ });
2099
+ }
2100
+
2101
+ toString () {
2102
+ return `${this.name} [${sym}]: ${this.message}`
2103
+ }
2104
+ };
2105
+ }
2106
+
2107
+ E('ERR_BUFFER_OUT_OF_BOUNDS',
2108
+ function (name) {
2109
+ if (name) {
2110
+ return `${name} is outside of buffer bounds`
2111
+ }
2112
+
2113
+ return 'Attempt to access memory outside buffer bounds'
2114
+ }, RangeError);
2115
+ E('ERR_INVALID_ARG_TYPE',
2116
+ function (name, actual) {
2117
+ return `The "${name}" argument must be of type number. Received type ${typeof actual}`
2118
+ }, TypeError);
2119
+ E('ERR_OUT_OF_RANGE',
2120
+ function (str, range, input) {
2121
+ let msg = `The value of "${str}" is out of range.`;
2122
+ let received = input;
2123
+ if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
2124
+ received = addNumericalSeparator(String(input));
2125
+ } else if (typeof input === 'bigint') {
2126
+ received = String(input);
2127
+ if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
2128
+ received = addNumericalSeparator(received);
2129
+ }
2130
+ received += 'n';
2131
+ }
2132
+ msg += ` It must be ${range}. Received ${received}`;
2133
+ return msg
2134
+ }, RangeError);
2135
+
2136
+ function addNumericalSeparator (val) {
2137
+ let res = '';
2138
+ let i = val.length;
2139
+ const start = val[0] === '-' ? 1 : 0;
2140
+ for (; i >= start + 4; i -= 3) {
2141
+ res = `_${val.slice(i - 3, i)}${res}`;
2142
+ }
2143
+ return `${val.slice(0, i)}${res}`
2144
+ }
2145
+
2146
+ // CHECK FUNCTIONS
2147
+ // ===============
2148
+
2149
+ function checkBounds (buf, offset, byteLength) {
2150
+ validateNumber(offset, 'offset');
2151
+ if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {
2152
+ boundsError(offset, buf.length - (byteLength + 1));
2153
+ }
2154
+ }
2155
+
2156
+ function checkIntBI (value, min, max, buf, offset, byteLength) {
2157
+ if (value > max || value < min) {
2158
+ const n = typeof min === 'bigint' ? 'n' : '';
2159
+ let range;
2160
+ {
2161
+ if (min === 0 || min === BigInt(0)) {
2162
+ range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`;
2163
+ } else {
2164
+ range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
2165
+ `${(byteLength + 1) * 8 - 1}${n}`;
2166
+ }
2167
+ }
2168
+ throw new errors.ERR_OUT_OF_RANGE('value', range, value)
2169
+ }
2170
+ checkBounds(buf, offset, byteLength);
2171
+ }
2172
+
2173
+ function validateNumber (value, name) {
2174
+ if (typeof value !== 'number') {
2175
+ throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value)
2176
+ }
2177
+ }
2178
+
2179
+ function boundsError (value, length, type) {
2180
+ if (Math.floor(value) !== value) {
2181
+ validateNumber(value, type);
2182
+ throw new errors.ERR_OUT_OF_RANGE('offset', 'an integer', value)
2183
+ }
2184
+
2185
+ if (length < 0) {
2186
+ throw new errors.ERR_BUFFER_OUT_OF_BOUNDS()
2187
+ }
2188
+
2189
+ throw new errors.ERR_OUT_OF_RANGE('offset',
2190
+ `>= ${0} and <= ${length}`,
2191
+ value)
2192
+ }
2193
+
2194
+ // HELPER FUNCTIONS
2195
+ // ================
2196
+
2197
+ const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
2198
+
2199
+ function base64clean (str) {
2200
+ // Node takes equal signs as end of the Base64 encoding
2201
+ str = str.split('=')[0];
2202
+ // Node strips out invalid characters like \n and \t from the string, base64-js does not
2203
+ str = str.trim().replace(INVALID_BASE64_RE, '');
2204
+ // Node converts strings with length < 2 to ''
2205
+ if (str.length < 2) return ''
2206
+ // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
2207
+ while (str.length % 4 !== 0) {
2208
+ str = str + '=';
2209
+ }
2210
+ return str
2211
+ }
2212
+
2213
+ function utf8ToBytes (string, units) {
2214
+ units = units || Infinity;
2215
+ let codePoint;
2216
+ const length = string.length;
2217
+ let leadSurrogate = null;
2218
+ const bytes = [];
2219
+
2220
+ for (let i = 0; i < length; ++i) {
2221
+ codePoint = string.charCodeAt(i);
2222
+
2223
+ // is surrogate component
2224
+ if (codePoint > 0xD7FF && codePoint < 0xE000) {
2225
+ // last char was a lead
2226
+ if (!leadSurrogate) {
2227
+ // no lead yet
2228
+ if (codePoint > 0xDBFF) {
2229
+ // unexpected trail
2230
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
2231
+ continue
2232
+ } else if (i + 1 === length) {
2233
+ // unpaired lead
2234
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
2235
+ continue
2236
+ }
2237
+
2238
+ // valid lead
2239
+ leadSurrogate = codePoint;
2240
+
2241
+ continue
2242
+ }
2243
+
2244
+ // 2 leads in a row
2245
+ if (codePoint < 0xDC00) {
2246
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
2247
+ leadSurrogate = codePoint;
2248
+ continue
2249
+ }
2250
+
2251
+ // valid surrogate pair
2252
+ codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
2253
+ } else if (leadSurrogate) {
2254
+ // valid bmp char, but last char was a lead
2255
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
2256
+ }
2257
+
2258
+ leadSurrogate = null;
2259
+
2260
+ // encode utf8
2261
+ if (codePoint < 0x80) {
2262
+ if ((units -= 1) < 0) break
2263
+ bytes.push(codePoint);
2264
+ } else if (codePoint < 0x800) {
2265
+ if ((units -= 2) < 0) break
2266
+ bytes.push(
2267
+ codePoint >> 0x6 | 0xC0,
2268
+ codePoint & 0x3F | 0x80
2269
+ );
2270
+ } else if (codePoint < 0x10000) {
2271
+ if ((units -= 3) < 0) break
2272
+ bytes.push(
2273
+ codePoint >> 0xC | 0xE0,
2274
+ codePoint >> 0x6 & 0x3F | 0x80,
2275
+ codePoint & 0x3F | 0x80
2276
+ );
2277
+ } else if (codePoint < 0x110000) {
2278
+ if ((units -= 4) < 0) break
2279
+ bytes.push(
2280
+ codePoint >> 0x12 | 0xF0,
2281
+ codePoint >> 0xC & 0x3F | 0x80,
2282
+ codePoint >> 0x6 & 0x3F | 0x80,
2283
+ codePoint & 0x3F | 0x80
2284
+ );
2285
+ } else {
2286
+ throw new Error('Invalid code point')
2287
+ }
2288
+ }
2289
+
2290
+ return bytes
2291
+ }
2292
+
2293
+ function asciiToBytes (str) {
2294
+ const byteArray = [];
2295
+ for (let i = 0; i < str.length; ++i) {
2296
+ // Node's code seems to be doing this and not & 0x7F..
2297
+ byteArray.push(str.charCodeAt(i) & 0xFF);
2298
+ }
2299
+ return byteArray
2300
+ }
2301
+
2302
+ function utf16leToBytes (str, units) {
2303
+ let c, hi, lo;
2304
+ const byteArray = [];
2305
+ for (let i = 0; i < str.length; ++i) {
2306
+ if ((units -= 2) < 0) break
2307
+
2308
+ c = str.charCodeAt(i);
2309
+ hi = c >> 8;
2310
+ lo = c % 256;
2311
+ byteArray.push(lo);
2312
+ byteArray.push(hi);
2313
+ }
2314
+
2315
+ return byteArray
2316
+ }
2317
+
2318
+ function base64ToBytes (str) {
2319
+ return base64.toByteArray(base64clean(str))
2320
+ }
2321
+
2322
+ function blitBuffer (src, dst, offset, length) {
2323
+ let i;
2324
+ for (i = 0; i < length; ++i) {
2325
+ if ((i + offset >= dst.length) || (i >= src.length)) break
2326
+ dst[i + offset] = src[i];
2327
+ }
2328
+ return i
2329
+ }
2330
+
2331
+ // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
2332
+ // the `instanceof` check but they should be treated as of that type.
2333
+ // See: https://github.com/feross/buffer/issues/166
2334
+ function isInstance (obj, type) {
2335
+ return obj instanceof type ||
2336
+ (obj != null && obj.constructor != null && obj.constructor.name != null &&
2337
+ obj.constructor.name === type.name)
2338
+ }
2339
+ function numberIsNaN (obj) {
2340
+ // For IE11 support
2341
+ return obj !== obj // eslint-disable-line no-self-compare
2342
+ }
2343
+
2344
+ // Create lookup table for `toString('hex')`
2345
+ // See: https://github.com/feross/buffer/issues/219
2346
+ const hexSliceLookupTable = (function () {
2347
+ const alphabet = '0123456789abcdef';
2348
+ const table = new Array(256);
2349
+ for (let i = 0; i < 16; ++i) {
2350
+ const i16 = i * 16;
2351
+ for (let j = 0; j < 16; ++j) {
2352
+ table[i16 + j] = alphabet[i] + alphabet[j];
2353
+ }
2354
+ }
2355
+ return table
2356
+ })();
2357
+
2358
+ // Return not function with Error if BigInt not supported
2359
+ function defineBigIntMethod (fn) {
2360
+ return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn
2361
+ }
2362
+
2363
+ function BufferBigIntNotDefined () {
2364
+ throw new Error('BigInt not supported')
2365
+ }
2366
+ } (buffer));
2367
+ return buffer;
2368
+ }
2369
+
2370
+ var bufferExports = requireBuffer();
2371
+
2372
+ export { bufferExports as b };
2373
+ //# sourceMappingURL=index-CrOVJFX9.esm.js.map