@dxos/esbuild-plugins 0.1.57-main.e87098f → 0.1.57

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