@powersync/common 1.42.0 → 1.43.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bundle.mjs CHANGED
@@ -1,11 +1,162 @@
1
1
  import { Mutex } from 'async-mutex';
2
- import { EventIterator } from 'event-iterator';
3
- import { Buffer } from 'buffer/';
4
2
 
5
3
  function getDefaultExportFromCjs (x) {
6
4
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
7
5
  }
8
6
 
7
+ var dom = {};
8
+
9
+ var eventIterator = {};
10
+
11
+ var hasRequiredEventIterator;
12
+
13
+ function requireEventIterator () {
14
+ if (hasRequiredEventIterator) return eventIterator;
15
+ hasRequiredEventIterator = 1;
16
+ Object.defineProperty(eventIterator, "__esModule", { value: true });
17
+ class EventQueue {
18
+ constructor() {
19
+ this.pullQueue = [];
20
+ this.pushQueue = [];
21
+ this.eventHandlers = {};
22
+ this.isPaused = false;
23
+ this.isStopped = false;
24
+ }
25
+ push(value) {
26
+ if (this.isStopped)
27
+ return;
28
+ const resolution = { value, done: false };
29
+ if (this.pullQueue.length) {
30
+ const placeholder = this.pullQueue.shift();
31
+ if (placeholder)
32
+ placeholder.resolve(resolution);
33
+ }
34
+ else {
35
+ this.pushQueue.push(Promise.resolve(resolution));
36
+ if (this.highWaterMark !== undefined &&
37
+ this.pushQueue.length >= this.highWaterMark &&
38
+ !this.isPaused) {
39
+ this.isPaused = true;
40
+ if (this.eventHandlers.highWater) {
41
+ this.eventHandlers.highWater();
42
+ }
43
+ else if (console) {
44
+ console.warn(`EventIterator queue reached ${this.pushQueue.length} items`);
45
+ }
46
+ }
47
+ }
48
+ }
49
+ stop() {
50
+ if (this.isStopped)
51
+ return;
52
+ this.isStopped = true;
53
+ this.remove();
54
+ for (const placeholder of this.pullQueue) {
55
+ placeholder.resolve({ value: undefined, done: true });
56
+ }
57
+ this.pullQueue.length = 0;
58
+ }
59
+ fail(error) {
60
+ if (this.isStopped)
61
+ return;
62
+ this.isStopped = true;
63
+ this.remove();
64
+ if (this.pullQueue.length) {
65
+ for (const placeholder of this.pullQueue) {
66
+ placeholder.reject(error);
67
+ }
68
+ this.pullQueue.length = 0;
69
+ }
70
+ else {
71
+ const rejection = Promise.reject(error);
72
+ /* Attach error handler to avoid leaking an unhandled promise rejection. */
73
+ rejection.catch(() => { });
74
+ this.pushQueue.push(rejection);
75
+ }
76
+ }
77
+ remove() {
78
+ Promise.resolve().then(() => {
79
+ if (this.removeCallback)
80
+ this.removeCallback();
81
+ });
82
+ }
83
+ [Symbol.asyncIterator]() {
84
+ return {
85
+ next: (value) => {
86
+ const result = this.pushQueue.shift();
87
+ if (result) {
88
+ if (this.lowWaterMark !== undefined &&
89
+ this.pushQueue.length <= this.lowWaterMark &&
90
+ this.isPaused) {
91
+ this.isPaused = false;
92
+ if (this.eventHandlers.lowWater) {
93
+ this.eventHandlers.lowWater();
94
+ }
95
+ }
96
+ return result;
97
+ }
98
+ else if (this.isStopped) {
99
+ return Promise.resolve({ value: undefined, done: true });
100
+ }
101
+ else {
102
+ return new Promise((resolve, reject) => {
103
+ this.pullQueue.push({ resolve, reject });
104
+ });
105
+ }
106
+ },
107
+ return: () => {
108
+ this.isStopped = true;
109
+ this.pushQueue.length = 0;
110
+ this.remove();
111
+ return Promise.resolve({ value: undefined, done: true });
112
+ },
113
+ };
114
+ }
115
+ }
116
+ class EventIterator {
117
+ constructor(listen, { highWaterMark = 100, lowWaterMark = 1 } = {}) {
118
+ const queue = new EventQueue();
119
+ queue.highWaterMark = highWaterMark;
120
+ queue.lowWaterMark = lowWaterMark;
121
+ queue.removeCallback =
122
+ listen({
123
+ push: value => queue.push(value),
124
+ stop: () => queue.stop(),
125
+ fail: error => queue.fail(error),
126
+ on: (event, fn) => {
127
+ queue.eventHandlers[event] = fn;
128
+ },
129
+ }) || (() => { });
130
+ this[Symbol.asyncIterator] = () => queue[Symbol.asyncIterator]();
131
+ Object.freeze(this);
132
+ }
133
+ }
134
+ eventIterator.EventIterator = EventIterator;
135
+ eventIterator.default = EventIterator;
136
+ return eventIterator;
137
+ }
138
+
139
+ var hasRequiredDom;
140
+
141
+ function requireDom () {
142
+ if (hasRequiredDom) return dom;
143
+ hasRequiredDom = 1;
144
+ Object.defineProperty(dom, "__esModule", { value: true });
145
+ const event_iterator_1 = requireEventIterator();
146
+ dom.EventIterator = event_iterator_1.EventIterator;
147
+ function subscribe(event, options, evOptions) {
148
+ return new event_iterator_1.EventIterator(({ push }) => {
149
+ this.addEventListener(event, push, options);
150
+ return () => this.removeEventListener(event, push, options);
151
+ }, evOptions);
152
+ }
153
+ dom.subscribe = subscribe;
154
+ dom.default = event_iterator_1.EventIterator;
155
+ return dom;
156
+ }
157
+
158
+ var domExports = requireDom();
159
+
9
160
  var logger$1 = {exports: {}};
10
161
 
11
162
  /*!
@@ -1918,7 +2069,4207 @@ class SyncDataBucket {
1918
2069
  }
1919
2070
  }
1920
2071
 
1921
- var dist = {};
2072
+ var buffer$1 = {};
2073
+
2074
+ var base64Js = {};
2075
+
2076
+ var hasRequiredBase64Js;
2077
+
2078
+ function requireBase64Js () {
2079
+ if (hasRequiredBase64Js) return base64Js;
2080
+ hasRequiredBase64Js = 1;
2081
+
2082
+ base64Js.byteLength = byteLength;
2083
+ base64Js.toByteArray = toByteArray;
2084
+ base64Js.fromByteArray = fromByteArray;
2085
+
2086
+ var lookup = [];
2087
+ var revLookup = [];
2088
+ var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
2089
+
2090
+ var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
2091
+ for (var i = 0, len = code.length; i < len; ++i) {
2092
+ lookup[i] = code[i];
2093
+ revLookup[code.charCodeAt(i)] = i;
2094
+ }
2095
+
2096
+ // Support decoding URL-safe base64 strings, as Node.js does.
2097
+ // See: https://en.wikipedia.org/wiki/Base64#URL_applications
2098
+ revLookup['-'.charCodeAt(0)] = 62;
2099
+ revLookup['_'.charCodeAt(0)] = 63;
2100
+
2101
+ function getLens (b64) {
2102
+ var len = b64.length;
2103
+
2104
+ if (len % 4 > 0) {
2105
+ throw new Error('Invalid string. Length must be a multiple of 4')
2106
+ }
2107
+
2108
+ // Trim off extra bytes after placeholder bytes are found
2109
+ // See: https://github.com/beatgammit/base64-js/issues/42
2110
+ var validLen = b64.indexOf('=');
2111
+ if (validLen === -1) validLen = len;
2112
+
2113
+ var placeHoldersLen = validLen === len
2114
+ ? 0
2115
+ : 4 - (validLen % 4);
2116
+
2117
+ return [validLen, placeHoldersLen]
2118
+ }
2119
+
2120
+ // base64 is 4/3 + up to two characters of the original data
2121
+ function byteLength (b64) {
2122
+ var lens = getLens(b64);
2123
+ var validLen = lens[0];
2124
+ var placeHoldersLen = lens[1];
2125
+ return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
2126
+ }
2127
+
2128
+ function _byteLength (b64, validLen, placeHoldersLen) {
2129
+ return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
2130
+ }
2131
+
2132
+ function toByteArray (b64) {
2133
+ var tmp;
2134
+ var lens = getLens(b64);
2135
+ var validLen = lens[0];
2136
+ var placeHoldersLen = lens[1];
2137
+
2138
+ var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
2139
+
2140
+ var curByte = 0;
2141
+
2142
+ // if there are placeholders, only get up to the last complete 4 chars
2143
+ var len = placeHoldersLen > 0
2144
+ ? validLen - 4
2145
+ : validLen;
2146
+
2147
+ var i;
2148
+ for (i = 0; i < len; i += 4) {
2149
+ tmp =
2150
+ (revLookup[b64.charCodeAt(i)] << 18) |
2151
+ (revLookup[b64.charCodeAt(i + 1)] << 12) |
2152
+ (revLookup[b64.charCodeAt(i + 2)] << 6) |
2153
+ revLookup[b64.charCodeAt(i + 3)];
2154
+ arr[curByte++] = (tmp >> 16) & 0xFF;
2155
+ arr[curByte++] = (tmp >> 8) & 0xFF;
2156
+ arr[curByte++] = tmp & 0xFF;
2157
+ }
2158
+
2159
+ if (placeHoldersLen === 2) {
2160
+ tmp =
2161
+ (revLookup[b64.charCodeAt(i)] << 2) |
2162
+ (revLookup[b64.charCodeAt(i + 1)] >> 4);
2163
+ arr[curByte++] = tmp & 0xFF;
2164
+ }
2165
+
2166
+ if (placeHoldersLen === 1) {
2167
+ tmp =
2168
+ (revLookup[b64.charCodeAt(i)] << 10) |
2169
+ (revLookup[b64.charCodeAt(i + 1)] << 4) |
2170
+ (revLookup[b64.charCodeAt(i + 2)] >> 2);
2171
+ arr[curByte++] = (tmp >> 8) & 0xFF;
2172
+ arr[curByte++] = tmp & 0xFF;
2173
+ }
2174
+
2175
+ return arr
2176
+ }
2177
+
2178
+ function tripletToBase64 (num) {
2179
+ return lookup[num >> 18 & 0x3F] +
2180
+ lookup[num >> 12 & 0x3F] +
2181
+ lookup[num >> 6 & 0x3F] +
2182
+ lookup[num & 0x3F]
2183
+ }
2184
+
2185
+ function encodeChunk (uint8, start, end) {
2186
+ var tmp;
2187
+ var output = [];
2188
+ for (var i = start; i < end; i += 3) {
2189
+ tmp =
2190
+ ((uint8[i] << 16) & 0xFF0000) +
2191
+ ((uint8[i + 1] << 8) & 0xFF00) +
2192
+ (uint8[i + 2] & 0xFF);
2193
+ output.push(tripletToBase64(tmp));
2194
+ }
2195
+ return output.join('')
2196
+ }
2197
+
2198
+ function fromByteArray (uint8) {
2199
+ var tmp;
2200
+ var len = uint8.length;
2201
+ var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
2202
+ var parts = [];
2203
+ var maxChunkLength = 16383; // must be multiple of 3
2204
+
2205
+ // go through the array every three bytes, we'll deal with trailing stuff later
2206
+ for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
2207
+ parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
2208
+ }
2209
+
2210
+ // pad the end with zeros, but make sure to not forget the extra bytes
2211
+ if (extraBytes === 1) {
2212
+ tmp = uint8[len - 1];
2213
+ parts.push(
2214
+ lookup[tmp >> 2] +
2215
+ lookup[(tmp << 4) & 0x3F] +
2216
+ '=='
2217
+ );
2218
+ } else if (extraBytes === 2) {
2219
+ tmp = (uint8[len - 2] << 8) + uint8[len - 1];
2220
+ parts.push(
2221
+ lookup[tmp >> 10] +
2222
+ lookup[(tmp >> 4) & 0x3F] +
2223
+ lookup[(tmp << 2) & 0x3F] +
2224
+ '='
2225
+ );
2226
+ }
2227
+
2228
+ return parts.join('')
2229
+ }
2230
+ return base64Js;
2231
+ }
2232
+
2233
+ var ieee754 = {};
2234
+
2235
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
2236
+
2237
+ var hasRequiredIeee754;
2238
+
2239
+ function requireIeee754 () {
2240
+ if (hasRequiredIeee754) return ieee754;
2241
+ hasRequiredIeee754 = 1;
2242
+ ieee754.read = function (buffer, offset, isLE, mLen, nBytes) {
2243
+ var e, m;
2244
+ var eLen = (nBytes * 8) - mLen - 1;
2245
+ var eMax = (1 << eLen) - 1;
2246
+ var eBias = eMax >> 1;
2247
+ var nBits = -7;
2248
+ var i = isLE ? (nBytes - 1) : 0;
2249
+ var d = isLE ? -1 : 1;
2250
+ var s = buffer[offset + i];
2251
+
2252
+ i += d;
2253
+
2254
+ e = s & ((1 << (-nBits)) - 1);
2255
+ s >>= (-nBits);
2256
+ nBits += eLen;
2257
+ for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
2258
+
2259
+ m = e & ((1 << (-nBits)) - 1);
2260
+ e >>= (-nBits);
2261
+ nBits += mLen;
2262
+ for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
2263
+
2264
+ if (e === 0) {
2265
+ e = 1 - eBias;
2266
+ } else if (e === eMax) {
2267
+ return m ? NaN : ((s ? -1 : 1) * Infinity)
2268
+ } else {
2269
+ m = m + Math.pow(2, mLen);
2270
+ e = e - eBias;
2271
+ }
2272
+ return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
2273
+ };
2274
+
2275
+ ieee754.write = function (buffer, value, offset, isLE, mLen, nBytes) {
2276
+ var e, m, c;
2277
+ var eLen = (nBytes * 8) - mLen - 1;
2278
+ var eMax = (1 << eLen) - 1;
2279
+ var eBias = eMax >> 1;
2280
+ var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
2281
+ var i = isLE ? 0 : (nBytes - 1);
2282
+ var d = isLE ? 1 : -1;
2283
+ var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
2284
+
2285
+ value = Math.abs(value);
2286
+
2287
+ if (isNaN(value) || value === Infinity) {
2288
+ m = isNaN(value) ? 1 : 0;
2289
+ e = eMax;
2290
+ } else {
2291
+ e = Math.floor(Math.log(value) / Math.LN2);
2292
+ if (value * (c = Math.pow(2, -e)) < 1) {
2293
+ e--;
2294
+ c *= 2;
2295
+ }
2296
+ if (e + eBias >= 1) {
2297
+ value += rt / c;
2298
+ } else {
2299
+ value += rt * Math.pow(2, 1 - eBias);
2300
+ }
2301
+ if (value * c >= 2) {
2302
+ e++;
2303
+ c /= 2;
2304
+ }
2305
+
2306
+ if (e + eBias >= eMax) {
2307
+ m = 0;
2308
+ e = eMax;
2309
+ } else if (e + eBias >= 1) {
2310
+ m = ((value * c) - 1) * Math.pow(2, mLen);
2311
+ e = e + eBias;
2312
+ } else {
2313
+ m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
2314
+ e = 0;
2315
+ }
2316
+ }
2317
+
2318
+ for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
2319
+
2320
+ e = (e << mLen) | m;
2321
+ eLen += mLen;
2322
+ for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
2323
+
2324
+ buffer[offset + i - d] |= s * 128;
2325
+ };
2326
+ return ieee754;
2327
+ }
2328
+
2329
+ /*!
2330
+ * The buffer module from node.js, for the browser.
2331
+ *
2332
+ * @author Feross Aboukhadijeh <https://feross.org>
2333
+ * @license MIT
2334
+ */
2335
+
2336
+ var hasRequiredBuffer$1;
2337
+
2338
+ function requireBuffer$1 () {
2339
+ if (hasRequiredBuffer$1) return buffer$1;
2340
+ hasRequiredBuffer$1 = 1;
2341
+ (function (exports) {
2342
+
2343
+ const base64 = requireBase64Js();
2344
+ const ieee754 = requireIeee754();
2345
+ const customInspectSymbol =
2346
+ (typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation
2347
+ ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
2348
+ : null;
2349
+
2350
+ exports.Buffer = Buffer;
2351
+ exports.SlowBuffer = SlowBuffer;
2352
+ exports.INSPECT_MAX_BYTES = 50;
2353
+
2354
+ const K_MAX_LENGTH = 0x7fffffff;
2355
+ exports.kMaxLength = K_MAX_LENGTH;
2356
+
2357
+ /**
2358
+ * If `Buffer.TYPED_ARRAY_SUPPORT`:
2359
+ * === true Use Uint8Array implementation (fastest)
2360
+ * === false Print warning and recommend using `buffer` v4.x which has an Object
2361
+ * implementation (most compatible, even IE6)
2362
+ *
2363
+ * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
2364
+ * Opera 11.6+, iOS 4.2+.
2365
+ *
2366
+ * We report that the browser does not support typed arrays if the are not subclassable
2367
+ * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
2368
+ * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
2369
+ * for __proto__ and has a buggy typed array implementation.
2370
+ */
2371
+ Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
2372
+
2373
+ if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
2374
+ typeof console.error === 'function') {
2375
+ console.error(
2376
+ 'This browser lacks typed array (Uint8Array) support which is required by ' +
2377
+ '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
2378
+ );
2379
+ }
2380
+
2381
+ function typedArraySupport () {
2382
+ // Can typed array instances can be augmented?
2383
+ try {
2384
+ const arr = new Uint8Array(1);
2385
+ const proto = { foo: function () { return 42 } };
2386
+ Object.setPrototypeOf(proto, Uint8Array.prototype);
2387
+ Object.setPrototypeOf(arr, proto);
2388
+ return arr.foo() === 42
2389
+ } catch (e) {
2390
+ return false
2391
+ }
2392
+ }
2393
+
2394
+ Object.defineProperty(Buffer.prototype, 'parent', {
2395
+ enumerable: true,
2396
+ get: function () {
2397
+ if (!Buffer.isBuffer(this)) return undefined
2398
+ return this.buffer
2399
+ }
2400
+ });
2401
+
2402
+ Object.defineProperty(Buffer.prototype, 'offset', {
2403
+ enumerable: true,
2404
+ get: function () {
2405
+ if (!Buffer.isBuffer(this)) return undefined
2406
+ return this.byteOffset
2407
+ }
2408
+ });
2409
+
2410
+ function createBuffer (length) {
2411
+ if (length > K_MAX_LENGTH) {
2412
+ throw new RangeError('The value "' + length + '" is invalid for option "size"')
2413
+ }
2414
+ // Return an augmented `Uint8Array` instance
2415
+ const buf = new Uint8Array(length);
2416
+ Object.setPrototypeOf(buf, Buffer.prototype);
2417
+ return buf
2418
+ }
2419
+
2420
+ /**
2421
+ * The Buffer constructor returns instances of `Uint8Array` that have their
2422
+ * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
2423
+ * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
2424
+ * and the `Uint8Array` methods. Square bracket notation works as expected -- it
2425
+ * returns a single octet.
2426
+ *
2427
+ * The `Uint8Array` prototype remains unmodified.
2428
+ */
2429
+
2430
+ function Buffer (arg, encodingOrOffset, length) {
2431
+ // Common case.
2432
+ if (typeof arg === 'number') {
2433
+ if (typeof encodingOrOffset === 'string') {
2434
+ throw new TypeError(
2435
+ 'The "string" argument must be of type string. Received type number'
2436
+ )
2437
+ }
2438
+ return allocUnsafe(arg)
2439
+ }
2440
+ return from(arg, encodingOrOffset, length)
2441
+ }
2442
+
2443
+ Buffer.poolSize = 8192; // not used by this implementation
2444
+
2445
+ function from (value, encodingOrOffset, length) {
2446
+ if (typeof value === 'string') {
2447
+ return fromString(value, encodingOrOffset)
2448
+ }
2449
+
2450
+ if (ArrayBuffer.isView(value)) {
2451
+ return fromArrayView(value)
2452
+ }
2453
+
2454
+ if (value == null) {
2455
+ throw new TypeError(
2456
+ 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
2457
+ 'or Array-like Object. Received type ' + (typeof value)
2458
+ )
2459
+ }
2460
+
2461
+ if (isInstance(value, ArrayBuffer) ||
2462
+ (value && isInstance(value.buffer, ArrayBuffer))) {
2463
+ return fromArrayBuffer(value, encodingOrOffset, length)
2464
+ }
2465
+
2466
+ if (typeof SharedArrayBuffer !== 'undefined' &&
2467
+ (isInstance(value, SharedArrayBuffer) ||
2468
+ (value && isInstance(value.buffer, SharedArrayBuffer)))) {
2469
+ return fromArrayBuffer(value, encodingOrOffset, length)
2470
+ }
2471
+
2472
+ if (typeof value === 'number') {
2473
+ throw new TypeError(
2474
+ 'The "value" argument must not be of type number. Received type number'
2475
+ )
2476
+ }
2477
+
2478
+ const valueOf = value.valueOf && value.valueOf();
2479
+ if (valueOf != null && valueOf !== value) {
2480
+ return Buffer.from(valueOf, encodingOrOffset, length)
2481
+ }
2482
+
2483
+ const b = fromObject(value);
2484
+ if (b) return b
2485
+
2486
+ if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
2487
+ typeof value[Symbol.toPrimitive] === 'function') {
2488
+ return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length)
2489
+ }
2490
+
2491
+ throw new TypeError(
2492
+ 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
2493
+ 'or Array-like Object. Received type ' + (typeof value)
2494
+ )
2495
+ }
2496
+
2497
+ /**
2498
+ * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
2499
+ * if value is a number.
2500
+ * Buffer.from(str[, encoding])
2501
+ * Buffer.from(array)
2502
+ * Buffer.from(buffer)
2503
+ * Buffer.from(arrayBuffer[, byteOffset[, length]])
2504
+ **/
2505
+ Buffer.from = function (value, encodingOrOffset, length) {
2506
+ return from(value, encodingOrOffset, length)
2507
+ };
2508
+
2509
+ // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
2510
+ // https://github.com/feross/buffer/pull/148
2511
+ Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
2512
+ Object.setPrototypeOf(Buffer, Uint8Array);
2513
+
2514
+ function assertSize (size) {
2515
+ if (typeof size !== 'number') {
2516
+ throw new TypeError('"size" argument must be of type number')
2517
+ } else if (size < 0) {
2518
+ throw new RangeError('The value "' + size + '" is invalid for option "size"')
2519
+ }
2520
+ }
2521
+
2522
+ function alloc (size, fill, encoding) {
2523
+ assertSize(size);
2524
+ if (size <= 0) {
2525
+ return createBuffer(size)
2526
+ }
2527
+ if (fill !== undefined) {
2528
+ // Only pay attention to encoding if it's a string. This
2529
+ // prevents accidentally sending in a number that would
2530
+ // be interpreted as a start offset.
2531
+ return typeof encoding === 'string'
2532
+ ? createBuffer(size).fill(fill, encoding)
2533
+ : createBuffer(size).fill(fill)
2534
+ }
2535
+ return createBuffer(size)
2536
+ }
2537
+
2538
+ /**
2539
+ * Creates a new filled Buffer instance.
2540
+ * alloc(size[, fill[, encoding]])
2541
+ **/
2542
+ Buffer.alloc = function (size, fill, encoding) {
2543
+ return alloc(size, fill, encoding)
2544
+ };
2545
+
2546
+ function allocUnsafe (size) {
2547
+ assertSize(size);
2548
+ return createBuffer(size < 0 ? 0 : checked(size) | 0)
2549
+ }
2550
+
2551
+ /**
2552
+ * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
2553
+ * */
2554
+ Buffer.allocUnsafe = function (size) {
2555
+ return allocUnsafe(size)
2556
+ };
2557
+ /**
2558
+ * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
2559
+ */
2560
+ Buffer.allocUnsafeSlow = function (size) {
2561
+ return allocUnsafe(size)
2562
+ };
2563
+
2564
+ function fromString (string, encoding) {
2565
+ if (typeof encoding !== 'string' || encoding === '') {
2566
+ encoding = 'utf8';
2567
+ }
2568
+
2569
+ if (!Buffer.isEncoding(encoding)) {
2570
+ throw new TypeError('Unknown encoding: ' + encoding)
2571
+ }
2572
+
2573
+ const length = byteLength(string, encoding) | 0;
2574
+ let buf = createBuffer(length);
2575
+
2576
+ const actual = buf.write(string, encoding);
2577
+
2578
+ if (actual !== length) {
2579
+ // Writing a hex string, for example, that contains invalid characters will
2580
+ // cause everything after the first invalid character to be ignored. (e.g.
2581
+ // 'abxxcd' will be treated as 'ab')
2582
+ buf = buf.slice(0, actual);
2583
+ }
2584
+
2585
+ return buf
2586
+ }
2587
+
2588
+ function fromArrayLike (array) {
2589
+ const length = array.length < 0 ? 0 : checked(array.length) | 0;
2590
+ const buf = createBuffer(length);
2591
+ for (let i = 0; i < length; i += 1) {
2592
+ buf[i] = array[i] & 255;
2593
+ }
2594
+ return buf
2595
+ }
2596
+
2597
+ function fromArrayView (arrayView) {
2598
+ if (isInstance(arrayView, Uint8Array)) {
2599
+ const copy = new Uint8Array(arrayView);
2600
+ return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)
2601
+ }
2602
+ return fromArrayLike(arrayView)
2603
+ }
2604
+
2605
+ function fromArrayBuffer (array, byteOffset, length) {
2606
+ if (byteOffset < 0 || array.byteLength < byteOffset) {
2607
+ throw new RangeError('"offset" is outside of buffer bounds')
2608
+ }
2609
+
2610
+ if (array.byteLength < byteOffset + (length || 0)) {
2611
+ throw new RangeError('"length" is outside of buffer bounds')
2612
+ }
2613
+
2614
+ let buf;
2615
+ if (byteOffset === undefined && length === undefined) {
2616
+ buf = new Uint8Array(array);
2617
+ } else if (length === undefined) {
2618
+ buf = new Uint8Array(array, byteOffset);
2619
+ } else {
2620
+ buf = new Uint8Array(array, byteOffset, length);
2621
+ }
2622
+
2623
+ // Return an augmented `Uint8Array` instance
2624
+ Object.setPrototypeOf(buf, Buffer.prototype);
2625
+
2626
+ return buf
2627
+ }
2628
+
2629
+ function fromObject (obj) {
2630
+ if (Buffer.isBuffer(obj)) {
2631
+ const len = checked(obj.length) | 0;
2632
+ const buf = createBuffer(len);
2633
+
2634
+ if (buf.length === 0) {
2635
+ return buf
2636
+ }
2637
+
2638
+ obj.copy(buf, 0, 0, len);
2639
+ return buf
2640
+ }
2641
+
2642
+ if (obj.length !== undefined) {
2643
+ if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
2644
+ return createBuffer(0)
2645
+ }
2646
+ return fromArrayLike(obj)
2647
+ }
2648
+
2649
+ if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
2650
+ return fromArrayLike(obj.data)
2651
+ }
2652
+ }
2653
+
2654
+ function checked (length) {
2655
+ // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
2656
+ // length is NaN (which is otherwise coerced to zero.)
2657
+ if (length >= K_MAX_LENGTH) {
2658
+ throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
2659
+ 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
2660
+ }
2661
+ return length | 0
2662
+ }
2663
+
2664
+ function SlowBuffer (length) {
2665
+ if (+length != length) { // eslint-disable-line eqeqeq
2666
+ length = 0;
2667
+ }
2668
+ return Buffer.alloc(+length)
2669
+ }
2670
+
2671
+ Buffer.isBuffer = function isBuffer (b) {
2672
+ return b != null && b._isBuffer === true &&
2673
+ b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
2674
+ };
2675
+
2676
+ Buffer.compare = function compare (a, b) {
2677
+ if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);
2678
+ if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);
2679
+ if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
2680
+ throw new TypeError(
2681
+ 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
2682
+ )
2683
+ }
2684
+
2685
+ if (a === b) return 0
2686
+
2687
+ let x = a.length;
2688
+ let y = b.length;
2689
+
2690
+ for (let i = 0, len = Math.min(x, y); i < len; ++i) {
2691
+ if (a[i] !== b[i]) {
2692
+ x = a[i];
2693
+ y = b[i];
2694
+ break
2695
+ }
2696
+ }
2697
+
2698
+ if (x < y) return -1
2699
+ if (y < x) return 1
2700
+ return 0
2701
+ };
2702
+
2703
+ Buffer.isEncoding = function isEncoding (encoding) {
2704
+ switch (String(encoding).toLowerCase()) {
2705
+ case 'hex':
2706
+ case 'utf8':
2707
+ case 'utf-8':
2708
+ case 'ascii':
2709
+ case 'latin1':
2710
+ case 'binary':
2711
+ case 'base64':
2712
+ case 'ucs2':
2713
+ case 'ucs-2':
2714
+ case 'utf16le':
2715
+ case 'utf-16le':
2716
+ return true
2717
+ default:
2718
+ return false
2719
+ }
2720
+ };
2721
+
2722
+ Buffer.concat = function concat (list, length) {
2723
+ if (!Array.isArray(list)) {
2724
+ throw new TypeError('"list" argument must be an Array of Buffers')
2725
+ }
2726
+
2727
+ if (list.length === 0) {
2728
+ return Buffer.alloc(0)
2729
+ }
2730
+
2731
+ let i;
2732
+ if (length === undefined) {
2733
+ length = 0;
2734
+ for (i = 0; i < list.length; ++i) {
2735
+ length += list[i].length;
2736
+ }
2737
+ }
2738
+
2739
+ const buffer = Buffer.allocUnsafe(length);
2740
+ let pos = 0;
2741
+ for (i = 0; i < list.length; ++i) {
2742
+ let buf = list[i];
2743
+ if (isInstance(buf, Uint8Array)) {
2744
+ if (pos + buf.length > buffer.length) {
2745
+ if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf);
2746
+ buf.copy(buffer, pos);
2747
+ } else {
2748
+ Uint8Array.prototype.set.call(
2749
+ buffer,
2750
+ buf,
2751
+ pos
2752
+ );
2753
+ }
2754
+ } else if (!Buffer.isBuffer(buf)) {
2755
+ throw new TypeError('"list" argument must be an Array of Buffers')
2756
+ } else {
2757
+ buf.copy(buffer, pos);
2758
+ }
2759
+ pos += buf.length;
2760
+ }
2761
+ return buffer
2762
+ };
2763
+
2764
+ function byteLength (string, encoding) {
2765
+ if (Buffer.isBuffer(string)) {
2766
+ return string.length
2767
+ }
2768
+ if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
2769
+ return string.byteLength
2770
+ }
2771
+ if (typeof string !== 'string') {
2772
+ throw new TypeError(
2773
+ 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
2774
+ 'Received type ' + typeof string
2775
+ )
2776
+ }
2777
+
2778
+ const len = string.length;
2779
+ const mustMatch = (arguments.length > 2 && arguments[2] === true);
2780
+ if (!mustMatch && len === 0) return 0
2781
+
2782
+ // Use a for loop to avoid recursion
2783
+ let loweredCase = false;
2784
+ for (;;) {
2785
+ switch (encoding) {
2786
+ case 'ascii':
2787
+ case 'latin1':
2788
+ case 'binary':
2789
+ return len
2790
+ case 'utf8':
2791
+ case 'utf-8':
2792
+ return utf8ToBytes(string).length
2793
+ case 'ucs2':
2794
+ case 'ucs-2':
2795
+ case 'utf16le':
2796
+ case 'utf-16le':
2797
+ return len * 2
2798
+ case 'hex':
2799
+ return len >>> 1
2800
+ case 'base64':
2801
+ return base64ToBytes(string).length
2802
+ default:
2803
+ if (loweredCase) {
2804
+ return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
2805
+ }
2806
+ encoding = ('' + encoding).toLowerCase();
2807
+ loweredCase = true;
2808
+ }
2809
+ }
2810
+ }
2811
+ Buffer.byteLength = byteLength;
2812
+
2813
+ function slowToString (encoding, start, end) {
2814
+ let loweredCase = false;
2815
+
2816
+ // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
2817
+ // property of a typed array.
2818
+
2819
+ // This behaves neither like String nor Uint8Array in that we set start/end
2820
+ // to their upper/lower bounds if the value passed is out of range.
2821
+ // undefined is handled specially as per ECMA-262 6th Edition,
2822
+ // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
2823
+ if (start === undefined || start < 0) {
2824
+ start = 0;
2825
+ }
2826
+ // Return early if start > this.length. Done here to prevent potential uint32
2827
+ // coercion fail below.
2828
+ if (start > this.length) {
2829
+ return ''
2830
+ }
2831
+
2832
+ if (end === undefined || end > this.length) {
2833
+ end = this.length;
2834
+ }
2835
+
2836
+ if (end <= 0) {
2837
+ return ''
2838
+ }
2839
+
2840
+ // Force coercion to uint32. This will also coerce falsey/NaN values to 0.
2841
+ end >>>= 0;
2842
+ start >>>= 0;
2843
+
2844
+ if (end <= start) {
2845
+ return ''
2846
+ }
2847
+
2848
+ if (!encoding) encoding = 'utf8';
2849
+
2850
+ while (true) {
2851
+ switch (encoding) {
2852
+ case 'hex':
2853
+ return hexSlice(this, start, end)
2854
+
2855
+ case 'utf8':
2856
+ case 'utf-8':
2857
+ return utf8Slice(this, start, end)
2858
+
2859
+ case 'ascii':
2860
+ return asciiSlice(this, start, end)
2861
+
2862
+ case 'latin1':
2863
+ case 'binary':
2864
+ return latin1Slice(this, start, end)
2865
+
2866
+ case 'base64':
2867
+ return base64Slice(this, start, end)
2868
+
2869
+ case 'ucs2':
2870
+ case 'ucs-2':
2871
+ case 'utf16le':
2872
+ case 'utf-16le':
2873
+ return utf16leSlice(this, start, end)
2874
+
2875
+ default:
2876
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
2877
+ encoding = (encoding + '').toLowerCase();
2878
+ loweredCase = true;
2879
+ }
2880
+ }
2881
+ }
2882
+
2883
+ // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
2884
+ // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
2885
+ // reliably in a browserify context because there could be multiple different
2886
+ // copies of the 'buffer' package in use. This method works even for Buffer
2887
+ // instances that were created from another copy of the `buffer` package.
2888
+ // See: https://github.com/feross/buffer/issues/154
2889
+ Buffer.prototype._isBuffer = true;
2890
+
2891
+ function swap (b, n, m) {
2892
+ const i = b[n];
2893
+ b[n] = b[m];
2894
+ b[m] = i;
2895
+ }
2896
+
2897
+ Buffer.prototype.swap16 = function swap16 () {
2898
+ const len = this.length;
2899
+ if (len % 2 !== 0) {
2900
+ throw new RangeError('Buffer size must be a multiple of 16-bits')
2901
+ }
2902
+ for (let i = 0; i < len; i += 2) {
2903
+ swap(this, i, i + 1);
2904
+ }
2905
+ return this
2906
+ };
2907
+
2908
+ Buffer.prototype.swap32 = function swap32 () {
2909
+ const len = this.length;
2910
+ if (len % 4 !== 0) {
2911
+ throw new RangeError('Buffer size must be a multiple of 32-bits')
2912
+ }
2913
+ for (let i = 0; i < len; i += 4) {
2914
+ swap(this, i, i + 3);
2915
+ swap(this, i + 1, i + 2);
2916
+ }
2917
+ return this
2918
+ };
2919
+
2920
+ Buffer.prototype.swap64 = function swap64 () {
2921
+ const len = this.length;
2922
+ if (len % 8 !== 0) {
2923
+ throw new RangeError('Buffer size must be a multiple of 64-bits')
2924
+ }
2925
+ for (let i = 0; i < len; i += 8) {
2926
+ swap(this, i, i + 7);
2927
+ swap(this, i + 1, i + 6);
2928
+ swap(this, i + 2, i + 5);
2929
+ swap(this, i + 3, i + 4);
2930
+ }
2931
+ return this
2932
+ };
2933
+
2934
+ Buffer.prototype.toString = function toString () {
2935
+ const length = this.length;
2936
+ if (length === 0) return ''
2937
+ if (arguments.length === 0) return utf8Slice(this, 0, length)
2938
+ return slowToString.apply(this, arguments)
2939
+ };
2940
+
2941
+ Buffer.prototype.toLocaleString = Buffer.prototype.toString;
2942
+
2943
+ Buffer.prototype.equals = function equals (b) {
2944
+ if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
2945
+ if (this === b) return true
2946
+ return Buffer.compare(this, b) === 0
2947
+ };
2948
+
2949
+ Buffer.prototype.inspect = function inspect () {
2950
+ let str = '';
2951
+ const max = exports.INSPECT_MAX_BYTES;
2952
+ str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
2953
+ if (this.length > max) str += ' ... ';
2954
+ return '<Buffer ' + str + '>'
2955
+ };
2956
+ if (customInspectSymbol) {
2957
+ Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
2958
+ }
2959
+
2960
+ Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
2961
+ if (isInstance(target, Uint8Array)) {
2962
+ target = Buffer.from(target, target.offset, target.byteLength);
2963
+ }
2964
+ if (!Buffer.isBuffer(target)) {
2965
+ throw new TypeError(
2966
+ 'The "target" argument must be one of type Buffer or Uint8Array. ' +
2967
+ 'Received type ' + (typeof target)
2968
+ )
2969
+ }
2970
+
2971
+ if (start === undefined) {
2972
+ start = 0;
2973
+ }
2974
+ if (end === undefined) {
2975
+ end = target ? target.length : 0;
2976
+ }
2977
+ if (thisStart === undefined) {
2978
+ thisStart = 0;
2979
+ }
2980
+ if (thisEnd === undefined) {
2981
+ thisEnd = this.length;
2982
+ }
2983
+
2984
+ if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
2985
+ throw new RangeError('out of range index')
2986
+ }
2987
+
2988
+ if (thisStart >= thisEnd && start >= end) {
2989
+ return 0
2990
+ }
2991
+ if (thisStart >= thisEnd) {
2992
+ return -1
2993
+ }
2994
+ if (start >= end) {
2995
+ return 1
2996
+ }
2997
+
2998
+ start >>>= 0;
2999
+ end >>>= 0;
3000
+ thisStart >>>= 0;
3001
+ thisEnd >>>= 0;
3002
+
3003
+ if (this === target) return 0
3004
+
3005
+ let x = thisEnd - thisStart;
3006
+ let y = end - start;
3007
+ const len = Math.min(x, y);
3008
+
3009
+ const thisCopy = this.slice(thisStart, thisEnd);
3010
+ const targetCopy = target.slice(start, end);
3011
+
3012
+ for (let i = 0; i < len; ++i) {
3013
+ if (thisCopy[i] !== targetCopy[i]) {
3014
+ x = thisCopy[i];
3015
+ y = targetCopy[i];
3016
+ break
3017
+ }
3018
+ }
3019
+
3020
+ if (x < y) return -1
3021
+ if (y < x) return 1
3022
+ return 0
3023
+ };
3024
+
3025
+ // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
3026
+ // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
3027
+ //
3028
+ // Arguments:
3029
+ // - buffer - a Buffer to search
3030
+ // - val - a string, Buffer, or number
3031
+ // - byteOffset - an index into `buffer`; will be clamped to an int32
3032
+ // - encoding - an optional encoding, relevant is val is a string
3033
+ // - dir - true for indexOf, false for lastIndexOf
3034
+ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
3035
+ // Empty buffer means no match
3036
+ if (buffer.length === 0) return -1
3037
+
3038
+ // Normalize byteOffset
3039
+ if (typeof byteOffset === 'string') {
3040
+ encoding = byteOffset;
3041
+ byteOffset = 0;
3042
+ } else if (byteOffset > 0x7fffffff) {
3043
+ byteOffset = 0x7fffffff;
3044
+ } else if (byteOffset < -2147483648) {
3045
+ byteOffset = -2147483648;
3046
+ }
3047
+ byteOffset = +byteOffset; // Coerce to Number.
3048
+ if (numberIsNaN(byteOffset)) {
3049
+ // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
3050
+ byteOffset = dir ? 0 : (buffer.length - 1);
3051
+ }
3052
+
3053
+ // Normalize byteOffset: negative offsets start from the end of the buffer
3054
+ if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
3055
+ if (byteOffset >= buffer.length) {
3056
+ if (dir) return -1
3057
+ else byteOffset = buffer.length - 1;
3058
+ } else if (byteOffset < 0) {
3059
+ if (dir) byteOffset = 0;
3060
+ else return -1
3061
+ }
3062
+
3063
+ // Normalize val
3064
+ if (typeof val === 'string') {
3065
+ val = Buffer.from(val, encoding);
3066
+ }
3067
+
3068
+ // Finally, search either indexOf (if dir is true) or lastIndexOf
3069
+ if (Buffer.isBuffer(val)) {
3070
+ // Special case: looking for empty string/buffer always fails
3071
+ if (val.length === 0) {
3072
+ return -1
3073
+ }
3074
+ return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
3075
+ } else if (typeof val === 'number') {
3076
+ val = val & 0xFF; // Search for a byte value [0-255]
3077
+ if (typeof Uint8Array.prototype.indexOf === 'function') {
3078
+ if (dir) {
3079
+ return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
3080
+ } else {
3081
+ return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
3082
+ }
3083
+ }
3084
+ return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
3085
+ }
3086
+
3087
+ throw new TypeError('val must be string, number or Buffer')
3088
+ }
3089
+
3090
+ function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
3091
+ let indexSize = 1;
3092
+ let arrLength = arr.length;
3093
+ let valLength = val.length;
3094
+
3095
+ if (encoding !== undefined) {
3096
+ encoding = String(encoding).toLowerCase();
3097
+ if (encoding === 'ucs2' || encoding === 'ucs-2' ||
3098
+ encoding === 'utf16le' || encoding === 'utf-16le') {
3099
+ if (arr.length < 2 || val.length < 2) {
3100
+ return -1
3101
+ }
3102
+ indexSize = 2;
3103
+ arrLength /= 2;
3104
+ valLength /= 2;
3105
+ byteOffset /= 2;
3106
+ }
3107
+ }
3108
+
3109
+ function read (buf, i) {
3110
+ if (indexSize === 1) {
3111
+ return buf[i]
3112
+ } else {
3113
+ return buf.readUInt16BE(i * indexSize)
3114
+ }
3115
+ }
3116
+
3117
+ let i;
3118
+ if (dir) {
3119
+ let foundIndex = -1;
3120
+ for (i = byteOffset; i < arrLength; i++) {
3121
+ if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
3122
+ if (foundIndex === -1) foundIndex = i;
3123
+ if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
3124
+ } else {
3125
+ if (foundIndex !== -1) i -= i - foundIndex;
3126
+ foundIndex = -1;
3127
+ }
3128
+ }
3129
+ } else {
3130
+ if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
3131
+ for (i = byteOffset; i >= 0; i--) {
3132
+ let found = true;
3133
+ for (let j = 0; j < valLength; j++) {
3134
+ if (read(arr, i + j) !== read(val, j)) {
3135
+ found = false;
3136
+ break
3137
+ }
3138
+ }
3139
+ if (found) return i
3140
+ }
3141
+ }
3142
+
3143
+ return -1
3144
+ }
3145
+
3146
+ Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
3147
+ return this.indexOf(val, byteOffset, encoding) !== -1
3148
+ };
3149
+
3150
+ Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
3151
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
3152
+ };
3153
+
3154
+ Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
3155
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
3156
+ };
3157
+
3158
+ function hexWrite (buf, string, offset, length) {
3159
+ offset = Number(offset) || 0;
3160
+ const remaining = buf.length - offset;
3161
+ if (!length) {
3162
+ length = remaining;
3163
+ } else {
3164
+ length = Number(length);
3165
+ if (length > remaining) {
3166
+ length = remaining;
3167
+ }
3168
+ }
3169
+
3170
+ const strLen = string.length;
3171
+
3172
+ if (length > strLen / 2) {
3173
+ length = strLen / 2;
3174
+ }
3175
+ let i;
3176
+ for (i = 0; i < length; ++i) {
3177
+ const parsed = parseInt(string.substr(i * 2, 2), 16);
3178
+ if (numberIsNaN(parsed)) return i
3179
+ buf[offset + i] = parsed;
3180
+ }
3181
+ return i
3182
+ }
3183
+
3184
+ function utf8Write (buf, string, offset, length) {
3185
+ return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
3186
+ }
3187
+
3188
+ function asciiWrite (buf, string, offset, length) {
3189
+ return blitBuffer(asciiToBytes(string), buf, offset, length)
3190
+ }
3191
+
3192
+ function base64Write (buf, string, offset, length) {
3193
+ return blitBuffer(base64ToBytes(string), buf, offset, length)
3194
+ }
3195
+
3196
+ function ucs2Write (buf, string, offset, length) {
3197
+ return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
3198
+ }
3199
+
3200
+ Buffer.prototype.write = function write (string, offset, length, encoding) {
3201
+ // Buffer#write(string)
3202
+ if (offset === undefined) {
3203
+ encoding = 'utf8';
3204
+ length = this.length;
3205
+ offset = 0;
3206
+ // Buffer#write(string, encoding)
3207
+ } else if (length === undefined && typeof offset === 'string') {
3208
+ encoding = offset;
3209
+ length = this.length;
3210
+ offset = 0;
3211
+ // Buffer#write(string, offset[, length][, encoding])
3212
+ } else if (isFinite(offset)) {
3213
+ offset = offset >>> 0;
3214
+ if (isFinite(length)) {
3215
+ length = length >>> 0;
3216
+ if (encoding === undefined) encoding = 'utf8';
3217
+ } else {
3218
+ encoding = length;
3219
+ length = undefined;
3220
+ }
3221
+ } else {
3222
+ throw new Error(
3223
+ 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
3224
+ )
3225
+ }
3226
+
3227
+ const remaining = this.length - offset;
3228
+ if (length === undefined || length > remaining) length = remaining;
3229
+
3230
+ if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
3231
+ throw new RangeError('Attempt to write outside buffer bounds')
3232
+ }
3233
+
3234
+ if (!encoding) encoding = 'utf8';
3235
+
3236
+ let loweredCase = false;
3237
+ for (;;) {
3238
+ switch (encoding) {
3239
+ case 'hex':
3240
+ return hexWrite(this, string, offset, length)
3241
+
3242
+ case 'utf8':
3243
+ case 'utf-8':
3244
+ return utf8Write(this, string, offset, length)
3245
+
3246
+ case 'ascii':
3247
+ case 'latin1':
3248
+ case 'binary':
3249
+ return asciiWrite(this, string, offset, length)
3250
+
3251
+ case 'base64':
3252
+ // Warning: maxLength not taken into account in base64Write
3253
+ return base64Write(this, string, offset, length)
3254
+
3255
+ case 'ucs2':
3256
+ case 'ucs-2':
3257
+ case 'utf16le':
3258
+ case 'utf-16le':
3259
+ return ucs2Write(this, string, offset, length)
3260
+
3261
+ default:
3262
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
3263
+ encoding = ('' + encoding).toLowerCase();
3264
+ loweredCase = true;
3265
+ }
3266
+ }
3267
+ };
3268
+
3269
+ Buffer.prototype.toJSON = function toJSON () {
3270
+ return {
3271
+ type: 'Buffer',
3272
+ data: Array.prototype.slice.call(this._arr || this, 0)
3273
+ }
3274
+ };
3275
+
3276
+ function base64Slice (buf, start, end) {
3277
+ if (start === 0 && end === buf.length) {
3278
+ return base64.fromByteArray(buf)
3279
+ } else {
3280
+ return base64.fromByteArray(buf.slice(start, end))
3281
+ }
3282
+ }
3283
+
3284
+ function utf8Slice (buf, start, end) {
3285
+ end = Math.min(buf.length, end);
3286
+ const res = [];
3287
+
3288
+ let i = start;
3289
+ while (i < end) {
3290
+ const firstByte = buf[i];
3291
+ let codePoint = null;
3292
+ let bytesPerSequence = (firstByte > 0xEF)
3293
+ ? 4
3294
+ : (firstByte > 0xDF)
3295
+ ? 3
3296
+ : (firstByte > 0xBF)
3297
+ ? 2
3298
+ : 1;
3299
+
3300
+ if (i + bytesPerSequence <= end) {
3301
+ let secondByte, thirdByte, fourthByte, tempCodePoint;
3302
+
3303
+ switch (bytesPerSequence) {
3304
+ case 1:
3305
+ if (firstByte < 0x80) {
3306
+ codePoint = firstByte;
3307
+ }
3308
+ break
3309
+ case 2:
3310
+ secondByte = buf[i + 1];
3311
+ if ((secondByte & 0xC0) === 0x80) {
3312
+ tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
3313
+ if (tempCodePoint > 0x7F) {
3314
+ codePoint = tempCodePoint;
3315
+ }
3316
+ }
3317
+ break
3318
+ case 3:
3319
+ secondByte = buf[i + 1];
3320
+ thirdByte = buf[i + 2];
3321
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
3322
+ tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
3323
+ if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
3324
+ codePoint = tempCodePoint;
3325
+ }
3326
+ }
3327
+ break
3328
+ case 4:
3329
+ secondByte = buf[i + 1];
3330
+ thirdByte = buf[i + 2];
3331
+ fourthByte = buf[i + 3];
3332
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
3333
+ tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
3334
+ if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
3335
+ codePoint = tempCodePoint;
3336
+ }
3337
+ }
3338
+ }
3339
+ }
3340
+
3341
+ if (codePoint === null) {
3342
+ // we did not generate a valid codePoint so insert a
3343
+ // replacement char (U+FFFD) and advance only 1 byte
3344
+ codePoint = 0xFFFD;
3345
+ bytesPerSequence = 1;
3346
+ } else if (codePoint > 0xFFFF) {
3347
+ // encode to utf16 (surrogate pair dance)
3348
+ codePoint -= 0x10000;
3349
+ res.push(codePoint >>> 10 & 0x3FF | 0xD800);
3350
+ codePoint = 0xDC00 | codePoint & 0x3FF;
3351
+ }
3352
+
3353
+ res.push(codePoint);
3354
+ i += bytesPerSequence;
3355
+ }
3356
+
3357
+ return decodeCodePointsArray(res)
3358
+ }
3359
+
3360
+ // Based on http://stackoverflow.com/a/22747272/680742, the browser with
3361
+ // the lowest limit is Chrome, with 0x10000 args.
3362
+ // We go 1 magnitude less, for safety
3363
+ const MAX_ARGUMENTS_LENGTH = 0x1000;
3364
+
3365
+ function decodeCodePointsArray (codePoints) {
3366
+ const len = codePoints.length;
3367
+ if (len <= MAX_ARGUMENTS_LENGTH) {
3368
+ return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
3369
+ }
3370
+
3371
+ // Decode in chunks to avoid "call stack size exceeded".
3372
+ let res = '';
3373
+ let i = 0;
3374
+ while (i < len) {
3375
+ res += String.fromCharCode.apply(
3376
+ String,
3377
+ codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
3378
+ );
3379
+ }
3380
+ return res
3381
+ }
3382
+
3383
+ function asciiSlice (buf, start, end) {
3384
+ let ret = '';
3385
+ end = Math.min(buf.length, end);
3386
+
3387
+ for (let i = start; i < end; ++i) {
3388
+ ret += String.fromCharCode(buf[i] & 0x7F);
3389
+ }
3390
+ return ret
3391
+ }
3392
+
3393
+ function latin1Slice (buf, start, end) {
3394
+ let ret = '';
3395
+ end = Math.min(buf.length, end);
3396
+
3397
+ for (let i = start; i < end; ++i) {
3398
+ ret += String.fromCharCode(buf[i]);
3399
+ }
3400
+ return ret
3401
+ }
3402
+
3403
+ function hexSlice (buf, start, end) {
3404
+ const len = buf.length;
3405
+
3406
+ if (!start || start < 0) start = 0;
3407
+ if (!end || end < 0 || end > len) end = len;
3408
+
3409
+ let out = '';
3410
+ for (let i = start; i < end; ++i) {
3411
+ out += hexSliceLookupTable[buf[i]];
3412
+ }
3413
+ return out
3414
+ }
3415
+
3416
+ function utf16leSlice (buf, start, end) {
3417
+ const bytes = buf.slice(start, end);
3418
+ let res = '';
3419
+ // If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
3420
+ for (let i = 0; i < bytes.length - 1; i += 2) {
3421
+ res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256));
3422
+ }
3423
+ return res
3424
+ }
3425
+
3426
+ Buffer.prototype.slice = function slice (start, end) {
3427
+ const len = this.length;
3428
+ start = ~~start;
3429
+ end = end === undefined ? len : ~~end;
3430
+
3431
+ if (start < 0) {
3432
+ start += len;
3433
+ if (start < 0) start = 0;
3434
+ } else if (start > len) {
3435
+ start = len;
3436
+ }
3437
+
3438
+ if (end < 0) {
3439
+ end += len;
3440
+ if (end < 0) end = 0;
3441
+ } else if (end > len) {
3442
+ end = len;
3443
+ }
3444
+
3445
+ if (end < start) end = start;
3446
+
3447
+ const newBuf = this.subarray(start, end);
3448
+ // Return an augmented `Uint8Array` instance
3449
+ Object.setPrototypeOf(newBuf, Buffer.prototype);
3450
+
3451
+ return newBuf
3452
+ };
3453
+
3454
+ /*
3455
+ * Need to make sure that buffer isn't trying to write out of bounds.
3456
+ */
3457
+ function checkOffset (offset, ext, length) {
3458
+ if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
3459
+ if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
3460
+ }
3461
+
3462
+ Buffer.prototype.readUintLE =
3463
+ Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
3464
+ offset = offset >>> 0;
3465
+ byteLength = byteLength >>> 0;
3466
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
3467
+
3468
+ let val = this[offset];
3469
+ let mul = 1;
3470
+ let i = 0;
3471
+ while (++i < byteLength && (mul *= 0x100)) {
3472
+ val += this[offset + i] * mul;
3473
+ }
3474
+
3475
+ return val
3476
+ };
3477
+
3478
+ Buffer.prototype.readUintBE =
3479
+ Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
3480
+ offset = offset >>> 0;
3481
+ byteLength = byteLength >>> 0;
3482
+ if (!noAssert) {
3483
+ checkOffset(offset, byteLength, this.length);
3484
+ }
3485
+
3486
+ let val = this[offset + --byteLength];
3487
+ let mul = 1;
3488
+ while (byteLength > 0 && (mul *= 0x100)) {
3489
+ val += this[offset + --byteLength] * mul;
3490
+ }
3491
+
3492
+ return val
3493
+ };
3494
+
3495
+ Buffer.prototype.readUint8 =
3496
+ Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
3497
+ offset = offset >>> 0;
3498
+ if (!noAssert) checkOffset(offset, 1, this.length);
3499
+ return this[offset]
3500
+ };
3501
+
3502
+ Buffer.prototype.readUint16LE =
3503
+ Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
3504
+ offset = offset >>> 0;
3505
+ if (!noAssert) checkOffset(offset, 2, this.length);
3506
+ return this[offset] | (this[offset + 1] << 8)
3507
+ };
3508
+
3509
+ Buffer.prototype.readUint16BE =
3510
+ Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
3511
+ offset = offset >>> 0;
3512
+ if (!noAssert) checkOffset(offset, 2, this.length);
3513
+ return (this[offset] << 8) | this[offset + 1]
3514
+ };
3515
+
3516
+ Buffer.prototype.readUint32LE =
3517
+ Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
3518
+ offset = offset >>> 0;
3519
+ if (!noAssert) checkOffset(offset, 4, this.length);
3520
+
3521
+ return ((this[offset]) |
3522
+ (this[offset + 1] << 8) |
3523
+ (this[offset + 2] << 16)) +
3524
+ (this[offset + 3] * 0x1000000)
3525
+ };
3526
+
3527
+ Buffer.prototype.readUint32BE =
3528
+ Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
3529
+ offset = offset >>> 0;
3530
+ if (!noAssert) checkOffset(offset, 4, this.length);
3531
+
3532
+ return (this[offset] * 0x1000000) +
3533
+ ((this[offset + 1] << 16) |
3534
+ (this[offset + 2] << 8) |
3535
+ this[offset + 3])
3536
+ };
3537
+
3538
+ Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE (offset) {
3539
+ offset = offset >>> 0;
3540
+ validateNumber(offset, 'offset');
3541
+ const first = this[offset];
3542
+ const last = this[offset + 7];
3543
+ if (first === undefined || last === undefined) {
3544
+ boundsError(offset, this.length - 8);
3545
+ }
3546
+
3547
+ const lo = first +
3548
+ this[++offset] * 2 ** 8 +
3549
+ this[++offset] * 2 ** 16 +
3550
+ this[++offset] * 2 ** 24;
3551
+
3552
+ const hi = this[++offset] +
3553
+ this[++offset] * 2 ** 8 +
3554
+ this[++offset] * 2 ** 16 +
3555
+ last * 2 ** 24;
3556
+
3557
+ return BigInt(lo) + (BigInt(hi) << BigInt(32))
3558
+ });
3559
+
3560
+ Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE (offset) {
3561
+ offset = offset >>> 0;
3562
+ validateNumber(offset, 'offset');
3563
+ const first = this[offset];
3564
+ const last = this[offset + 7];
3565
+ if (first === undefined || last === undefined) {
3566
+ boundsError(offset, this.length - 8);
3567
+ }
3568
+
3569
+ const hi = first * 2 ** 24 +
3570
+ this[++offset] * 2 ** 16 +
3571
+ this[++offset] * 2 ** 8 +
3572
+ this[++offset];
3573
+
3574
+ const lo = this[++offset] * 2 ** 24 +
3575
+ this[++offset] * 2 ** 16 +
3576
+ this[++offset] * 2 ** 8 +
3577
+ last;
3578
+
3579
+ return (BigInt(hi) << BigInt(32)) + BigInt(lo)
3580
+ });
3581
+
3582
+ Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
3583
+ offset = offset >>> 0;
3584
+ byteLength = byteLength >>> 0;
3585
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
3586
+
3587
+ let val = this[offset];
3588
+ let mul = 1;
3589
+ let i = 0;
3590
+ while (++i < byteLength && (mul *= 0x100)) {
3591
+ val += this[offset + i] * mul;
3592
+ }
3593
+ mul *= 0x80;
3594
+
3595
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength);
3596
+
3597
+ return val
3598
+ };
3599
+
3600
+ Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
3601
+ offset = offset >>> 0;
3602
+ byteLength = byteLength >>> 0;
3603
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
3604
+
3605
+ let i = byteLength;
3606
+ let mul = 1;
3607
+ let val = this[offset + --i];
3608
+ while (i > 0 && (mul *= 0x100)) {
3609
+ val += this[offset + --i] * mul;
3610
+ }
3611
+ mul *= 0x80;
3612
+
3613
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength);
3614
+
3615
+ return val
3616
+ };
3617
+
3618
+ Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
3619
+ offset = offset >>> 0;
3620
+ if (!noAssert) checkOffset(offset, 1, this.length);
3621
+ if (!(this[offset] & 0x80)) return (this[offset])
3622
+ return ((0xff - this[offset] + 1) * -1)
3623
+ };
3624
+
3625
+ Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
3626
+ offset = offset >>> 0;
3627
+ if (!noAssert) checkOffset(offset, 2, this.length);
3628
+ const val = this[offset] | (this[offset + 1] << 8);
3629
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
3630
+ };
3631
+
3632
+ Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
3633
+ offset = offset >>> 0;
3634
+ if (!noAssert) checkOffset(offset, 2, this.length);
3635
+ const val = this[offset + 1] | (this[offset] << 8);
3636
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
3637
+ };
3638
+
3639
+ Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
3640
+ offset = offset >>> 0;
3641
+ if (!noAssert) checkOffset(offset, 4, this.length);
3642
+
3643
+ return (this[offset]) |
3644
+ (this[offset + 1] << 8) |
3645
+ (this[offset + 2] << 16) |
3646
+ (this[offset + 3] << 24)
3647
+ };
3648
+
3649
+ Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
3650
+ offset = offset >>> 0;
3651
+ if (!noAssert) checkOffset(offset, 4, this.length);
3652
+
3653
+ return (this[offset] << 24) |
3654
+ (this[offset + 1] << 16) |
3655
+ (this[offset + 2] << 8) |
3656
+ (this[offset + 3])
3657
+ };
3658
+
3659
+ Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE (offset) {
3660
+ offset = offset >>> 0;
3661
+ validateNumber(offset, 'offset');
3662
+ const first = this[offset];
3663
+ const last = this[offset + 7];
3664
+ if (first === undefined || last === undefined) {
3665
+ boundsError(offset, this.length - 8);
3666
+ }
3667
+
3668
+ const val = this[offset + 4] +
3669
+ this[offset + 5] * 2 ** 8 +
3670
+ this[offset + 6] * 2 ** 16 +
3671
+ (last << 24); // Overflow
3672
+
3673
+ return (BigInt(val) << BigInt(32)) +
3674
+ BigInt(first +
3675
+ this[++offset] * 2 ** 8 +
3676
+ this[++offset] * 2 ** 16 +
3677
+ this[++offset] * 2 ** 24)
3678
+ });
3679
+
3680
+ Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE (offset) {
3681
+ offset = offset >>> 0;
3682
+ validateNumber(offset, 'offset');
3683
+ const first = this[offset];
3684
+ const last = this[offset + 7];
3685
+ if (first === undefined || last === undefined) {
3686
+ boundsError(offset, this.length - 8);
3687
+ }
3688
+
3689
+ const val = (first << 24) + // Overflow
3690
+ this[++offset] * 2 ** 16 +
3691
+ this[++offset] * 2 ** 8 +
3692
+ this[++offset];
3693
+
3694
+ return (BigInt(val) << BigInt(32)) +
3695
+ BigInt(this[++offset] * 2 ** 24 +
3696
+ this[++offset] * 2 ** 16 +
3697
+ this[++offset] * 2 ** 8 +
3698
+ last)
3699
+ });
3700
+
3701
+ Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
3702
+ offset = offset >>> 0;
3703
+ if (!noAssert) checkOffset(offset, 4, this.length);
3704
+ return ieee754.read(this, offset, true, 23, 4)
3705
+ };
3706
+
3707
+ Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
3708
+ offset = offset >>> 0;
3709
+ if (!noAssert) checkOffset(offset, 4, this.length);
3710
+ return ieee754.read(this, offset, false, 23, 4)
3711
+ };
3712
+
3713
+ Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
3714
+ offset = offset >>> 0;
3715
+ if (!noAssert) checkOffset(offset, 8, this.length);
3716
+ return ieee754.read(this, offset, true, 52, 8)
3717
+ };
3718
+
3719
+ Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
3720
+ offset = offset >>> 0;
3721
+ if (!noAssert) checkOffset(offset, 8, this.length);
3722
+ return ieee754.read(this, offset, false, 52, 8)
3723
+ };
3724
+
3725
+ function checkInt (buf, value, offset, ext, max, min) {
3726
+ if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
3727
+ if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
3728
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
3729
+ }
3730
+
3731
+ Buffer.prototype.writeUintLE =
3732
+ Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
3733
+ value = +value;
3734
+ offset = offset >>> 0;
3735
+ byteLength = byteLength >>> 0;
3736
+ if (!noAssert) {
3737
+ const maxBytes = Math.pow(2, 8 * byteLength) - 1;
3738
+ checkInt(this, value, offset, byteLength, maxBytes, 0);
3739
+ }
3740
+
3741
+ let mul = 1;
3742
+ let i = 0;
3743
+ this[offset] = value & 0xFF;
3744
+ while (++i < byteLength && (mul *= 0x100)) {
3745
+ this[offset + i] = (value / mul) & 0xFF;
3746
+ }
3747
+
3748
+ return offset + byteLength
3749
+ };
3750
+
3751
+ Buffer.prototype.writeUintBE =
3752
+ Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
3753
+ value = +value;
3754
+ offset = offset >>> 0;
3755
+ byteLength = byteLength >>> 0;
3756
+ if (!noAssert) {
3757
+ const maxBytes = Math.pow(2, 8 * byteLength) - 1;
3758
+ checkInt(this, value, offset, byteLength, maxBytes, 0);
3759
+ }
3760
+
3761
+ let i = byteLength - 1;
3762
+ let mul = 1;
3763
+ this[offset + i] = value & 0xFF;
3764
+ while (--i >= 0 && (mul *= 0x100)) {
3765
+ this[offset + i] = (value / mul) & 0xFF;
3766
+ }
3767
+
3768
+ return offset + byteLength
3769
+ };
3770
+
3771
+ Buffer.prototype.writeUint8 =
3772
+ Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
3773
+ value = +value;
3774
+ offset = offset >>> 0;
3775
+ if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
3776
+ this[offset] = (value & 0xff);
3777
+ return offset + 1
3778
+ };
3779
+
3780
+ Buffer.prototype.writeUint16LE =
3781
+ Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
3782
+ value = +value;
3783
+ offset = offset >>> 0;
3784
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
3785
+ this[offset] = (value & 0xff);
3786
+ this[offset + 1] = (value >>> 8);
3787
+ return offset + 2
3788
+ };
3789
+
3790
+ Buffer.prototype.writeUint16BE =
3791
+ Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
3792
+ value = +value;
3793
+ offset = offset >>> 0;
3794
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
3795
+ this[offset] = (value >>> 8);
3796
+ this[offset + 1] = (value & 0xff);
3797
+ return offset + 2
3798
+ };
3799
+
3800
+ Buffer.prototype.writeUint32LE =
3801
+ Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
3802
+ value = +value;
3803
+ offset = offset >>> 0;
3804
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
3805
+ this[offset + 3] = (value >>> 24);
3806
+ this[offset + 2] = (value >>> 16);
3807
+ this[offset + 1] = (value >>> 8);
3808
+ this[offset] = (value & 0xff);
3809
+ return offset + 4
3810
+ };
3811
+
3812
+ Buffer.prototype.writeUint32BE =
3813
+ Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
3814
+ value = +value;
3815
+ offset = offset >>> 0;
3816
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
3817
+ this[offset] = (value >>> 24);
3818
+ this[offset + 1] = (value >>> 16);
3819
+ this[offset + 2] = (value >>> 8);
3820
+ this[offset + 3] = (value & 0xff);
3821
+ return offset + 4
3822
+ };
3823
+
3824
+ function wrtBigUInt64LE (buf, value, offset, min, max) {
3825
+ checkIntBI(value, min, max, buf, offset, 7);
3826
+
3827
+ let lo = Number(value & BigInt(0xffffffff));
3828
+ buf[offset++] = lo;
3829
+ lo = lo >> 8;
3830
+ buf[offset++] = lo;
3831
+ lo = lo >> 8;
3832
+ buf[offset++] = lo;
3833
+ lo = lo >> 8;
3834
+ buf[offset++] = lo;
3835
+ let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
3836
+ buf[offset++] = hi;
3837
+ hi = hi >> 8;
3838
+ buf[offset++] = hi;
3839
+ hi = hi >> 8;
3840
+ buf[offset++] = hi;
3841
+ hi = hi >> 8;
3842
+ buf[offset++] = hi;
3843
+ return offset
3844
+ }
3845
+
3846
+ function wrtBigUInt64BE (buf, value, offset, min, max) {
3847
+ checkIntBI(value, min, max, buf, offset, 7);
3848
+
3849
+ let lo = Number(value & BigInt(0xffffffff));
3850
+ buf[offset + 7] = lo;
3851
+ lo = lo >> 8;
3852
+ buf[offset + 6] = lo;
3853
+ lo = lo >> 8;
3854
+ buf[offset + 5] = lo;
3855
+ lo = lo >> 8;
3856
+ buf[offset + 4] = lo;
3857
+ let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
3858
+ buf[offset + 3] = hi;
3859
+ hi = hi >> 8;
3860
+ buf[offset + 2] = hi;
3861
+ hi = hi >> 8;
3862
+ buf[offset + 1] = hi;
3863
+ hi = hi >> 8;
3864
+ buf[offset] = hi;
3865
+ return offset + 8
3866
+ }
3867
+
3868
+ Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE (value, offset = 0) {
3869
+ return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
3870
+ });
3871
+
3872
+ Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE (value, offset = 0) {
3873
+ return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
3874
+ });
3875
+
3876
+ Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
3877
+ value = +value;
3878
+ offset = offset >>> 0;
3879
+ if (!noAssert) {
3880
+ const limit = Math.pow(2, (8 * byteLength) - 1);
3881
+
3882
+ checkInt(this, value, offset, byteLength, limit - 1, -limit);
3883
+ }
3884
+
3885
+ let i = 0;
3886
+ let mul = 1;
3887
+ let sub = 0;
3888
+ this[offset] = value & 0xFF;
3889
+ while (++i < byteLength && (mul *= 0x100)) {
3890
+ if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
3891
+ sub = 1;
3892
+ }
3893
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
3894
+ }
3895
+
3896
+ return offset + byteLength
3897
+ };
3898
+
3899
+ Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
3900
+ value = +value;
3901
+ offset = offset >>> 0;
3902
+ if (!noAssert) {
3903
+ const limit = Math.pow(2, (8 * byteLength) - 1);
3904
+
3905
+ checkInt(this, value, offset, byteLength, limit - 1, -limit);
3906
+ }
3907
+
3908
+ let i = byteLength - 1;
3909
+ let mul = 1;
3910
+ let sub = 0;
3911
+ this[offset + i] = value & 0xFF;
3912
+ while (--i >= 0 && (mul *= 0x100)) {
3913
+ if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
3914
+ sub = 1;
3915
+ }
3916
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
3917
+ }
3918
+
3919
+ return offset + byteLength
3920
+ };
3921
+
3922
+ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
3923
+ value = +value;
3924
+ offset = offset >>> 0;
3925
+ if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
3926
+ if (value < 0) value = 0xff + value + 1;
3927
+ this[offset] = (value & 0xff);
3928
+ return offset + 1
3929
+ };
3930
+
3931
+ Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
3932
+ value = +value;
3933
+ offset = offset >>> 0;
3934
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
3935
+ this[offset] = (value & 0xff);
3936
+ this[offset + 1] = (value >>> 8);
3937
+ return offset + 2
3938
+ };
3939
+
3940
+ Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
3941
+ value = +value;
3942
+ offset = offset >>> 0;
3943
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
3944
+ this[offset] = (value >>> 8);
3945
+ this[offset + 1] = (value & 0xff);
3946
+ return offset + 2
3947
+ };
3948
+
3949
+ Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
3950
+ value = +value;
3951
+ offset = offset >>> 0;
3952
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
3953
+ this[offset] = (value & 0xff);
3954
+ this[offset + 1] = (value >>> 8);
3955
+ this[offset + 2] = (value >>> 16);
3956
+ this[offset + 3] = (value >>> 24);
3957
+ return offset + 4
3958
+ };
3959
+
3960
+ Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
3961
+ value = +value;
3962
+ offset = offset >>> 0;
3963
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
3964
+ if (value < 0) value = 0xffffffff + value + 1;
3965
+ this[offset] = (value >>> 24);
3966
+ this[offset + 1] = (value >>> 16);
3967
+ this[offset + 2] = (value >>> 8);
3968
+ this[offset + 3] = (value & 0xff);
3969
+ return offset + 4
3970
+ };
3971
+
3972
+ Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE (value, offset = 0) {
3973
+ return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
3974
+ });
3975
+
3976
+ Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE (value, offset = 0) {
3977
+ return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
3978
+ });
3979
+
3980
+ function checkIEEE754 (buf, value, offset, ext, max, min) {
3981
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
3982
+ if (offset < 0) throw new RangeError('Index out of range')
3983
+ }
3984
+
3985
+ function writeFloat (buf, value, offset, littleEndian, noAssert) {
3986
+ value = +value;
3987
+ offset = offset >>> 0;
3988
+ if (!noAssert) {
3989
+ checkIEEE754(buf, value, offset, 4);
3990
+ }
3991
+ ieee754.write(buf, value, offset, littleEndian, 23, 4);
3992
+ return offset + 4
3993
+ }
3994
+
3995
+ Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
3996
+ return writeFloat(this, value, offset, true, noAssert)
3997
+ };
3998
+
3999
+ Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
4000
+ return writeFloat(this, value, offset, false, noAssert)
4001
+ };
4002
+
4003
+ function writeDouble (buf, value, offset, littleEndian, noAssert) {
4004
+ value = +value;
4005
+ offset = offset >>> 0;
4006
+ if (!noAssert) {
4007
+ checkIEEE754(buf, value, offset, 8);
4008
+ }
4009
+ ieee754.write(buf, value, offset, littleEndian, 52, 8);
4010
+ return offset + 8
4011
+ }
4012
+
4013
+ Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
4014
+ return writeDouble(this, value, offset, true, noAssert)
4015
+ };
4016
+
4017
+ Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
4018
+ return writeDouble(this, value, offset, false, noAssert)
4019
+ };
4020
+
4021
+ // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
4022
+ Buffer.prototype.copy = function copy (target, targetStart, start, end) {
4023
+ if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
4024
+ if (!start) start = 0;
4025
+ if (!end && end !== 0) end = this.length;
4026
+ if (targetStart >= target.length) targetStart = target.length;
4027
+ if (!targetStart) targetStart = 0;
4028
+ if (end > 0 && end < start) end = start;
4029
+
4030
+ // Copy 0 bytes; we're done
4031
+ if (end === start) return 0
4032
+ if (target.length === 0 || this.length === 0) return 0
4033
+
4034
+ // Fatal error conditions
4035
+ if (targetStart < 0) {
4036
+ throw new RangeError('targetStart out of bounds')
4037
+ }
4038
+ if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
4039
+ if (end < 0) throw new RangeError('sourceEnd out of bounds')
4040
+
4041
+ // Are we oob?
4042
+ if (end > this.length) end = this.length;
4043
+ if (target.length - targetStart < end - start) {
4044
+ end = target.length - targetStart + start;
4045
+ }
4046
+
4047
+ const len = end - start;
4048
+
4049
+ if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
4050
+ // Use built-in when available, missing from IE11
4051
+ this.copyWithin(targetStart, start, end);
4052
+ } else {
4053
+ Uint8Array.prototype.set.call(
4054
+ target,
4055
+ this.subarray(start, end),
4056
+ targetStart
4057
+ );
4058
+ }
4059
+
4060
+ return len
4061
+ };
4062
+
4063
+ // Usage:
4064
+ // buffer.fill(number[, offset[, end]])
4065
+ // buffer.fill(buffer[, offset[, end]])
4066
+ // buffer.fill(string[, offset[, end]][, encoding])
4067
+ Buffer.prototype.fill = function fill (val, start, end, encoding) {
4068
+ // Handle string cases:
4069
+ if (typeof val === 'string') {
4070
+ if (typeof start === 'string') {
4071
+ encoding = start;
4072
+ start = 0;
4073
+ end = this.length;
4074
+ } else if (typeof end === 'string') {
4075
+ encoding = end;
4076
+ end = this.length;
4077
+ }
4078
+ if (encoding !== undefined && typeof encoding !== 'string') {
4079
+ throw new TypeError('encoding must be a string')
4080
+ }
4081
+ if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
4082
+ throw new TypeError('Unknown encoding: ' + encoding)
4083
+ }
4084
+ if (val.length === 1) {
4085
+ const code = val.charCodeAt(0);
4086
+ if ((encoding === 'utf8' && code < 128) ||
4087
+ encoding === 'latin1') {
4088
+ // Fast path: If `val` fits into a single byte, use that numeric value.
4089
+ val = code;
4090
+ }
4091
+ }
4092
+ } else if (typeof val === 'number') {
4093
+ val = val & 255;
4094
+ } else if (typeof val === 'boolean') {
4095
+ val = Number(val);
4096
+ }
4097
+
4098
+ // Invalid ranges are not set to a default, so can range check early.
4099
+ if (start < 0 || this.length < start || this.length < end) {
4100
+ throw new RangeError('Out of range index')
4101
+ }
4102
+
4103
+ if (end <= start) {
4104
+ return this
4105
+ }
4106
+
4107
+ start = start >>> 0;
4108
+ end = end === undefined ? this.length : end >>> 0;
4109
+
4110
+ if (!val) val = 0;
4111
+
4112
+ let i;
4113
+ if (typeof val === 'number') {
4114
+ for (i = start; i < end; ++i) {
4115
+ this[i] = val;
4116
+ }
4117
+ } else {
4118
+ const bytes = Buffer.isBuffer(val)
4119
+ ? val
4120
+ : Buffer.from(val, encoding);
4121
+ const len = bytes.length;
4122
+ if (len === 0) {
4123
+ throw new TypeError('The value "' + val +
4124
+ '" is invalid for argument "value"')
4125
+ }
4126
+ for (i = 0; i < end - start; ++i) {
4127
+ this[i + start] = bytes[i % len];
4128
+ }
4129
+ }
4130
+
4131
+ return this
4132
+ };
4133
+
4134
+ // CUSTOM ERRORS
4135
+ // =============
4136
+
4137
+ // Simplified versions from Node, changed for Buffer-only usage
4138
+ const errors = {};
4139
+ function E (sym, getMessage, Base) {
4140
+ errors[sym] = class NodeError extends Base {
4141
+ constructor () {
4142
+ super();
4143
+
4144
+ Object.defineProperty(this, 'message', {
4145
+ value: getMessage.apply(this, arguments),
4146
+ writable: true,
4147
+ configurable: true
4148
+ });
4149
+
4150
+ // Add the error code to the name to include it in the stack trace.
4151
+ this.name = `${this.name} [${sym}]`;
4152
+ // Access the stack to generate the error message including the error code
4153
+ // from the name.
4154
+ this.stack; // eslint-disable-line no-unused-expressions
4155
+ // Reset the name to the actual name.
4156
+ delete this.name;
4157
+ }
4158
+
4159
+ get code () {
4160
+ return sym
4161
+ }
4162
+
4163
+ set code (value) {
4164
+ Object.defineProperty(this, 'code', {
4165
+ configurable: true,
4166
+ enumerable: true,
4167
+ value,
4168
+ writable: true
4169
+ });
4170
+ }
4171
+
4172
+ toString () {
4173
+ return `${this.name} [${sym}]: ${this.message}`
4174
+ }
4175
+ };
4176
+ }
4177
+
4178
+ E('ERR_BUFFER_OUT_OF_BOUNDS',
4179
+ function (name) {
4180
+ if (name) {
4181
+ return `${name} is outside of buffer bounds`
4182
+ }
4183
+
4184
+ return 'Attempt to access memory outside buffer bounds'
4185
+ }, RangeError);
4186
+ E('ERR_INVALID_ARG_TYPE',
4187
+ function (name, actual) {
4188
+ return `The "${name}" argument must be of type number. Received type ${typeof actual}`
4189
+ }, TypeError);
4190
+ E('ERR_OUT_OF_RANGE',
4191
+ function (str, range, input) {
4192
+ let msg = `The value of "${str}" is out of range.`;
4193
+ let received = input;
4194
+ if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
4195
+ received = addNumericalSeparator(String(input));
4196
+ } else if (typeof input === 'bigint') {
4197
+ received = String(input);
4198
+ if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
4199
+ received = addNumericalSeparator(received);
4200
+ }
4201
+ received += 'n';
4202
+ }
4203
+ msg += ` It must be ${range}. Received ${received}`;
4204
+ return msg
4205
+ }, RangeError);
4206
+
4207
+ function addNumericalSeparator (val) {
4208
+ let res = '';
4209
+ let i = val.length;
4210
+ const start = val[0] === '-' ? 1 : 0;
4211
+ for (; i >= start + 4; i -= 3) {
4212
+ res = `_${val.slice(i - 3, i)}${res}`;
4213
+ }
4214
+ return `${val.slice(0, i)}${res}`
4215
+ }
4216
+
4217
+ // CHECK FUNCTIONS
4218
+ // ===============
4219
+
4220
+ function checkBounds (buf, offset, byteLength) {
4221
+ validateNumber(offset, 'offset');
4222
+ if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {
4223
+ boundsError(offset, buf.length - (byteLength + 1));
4224
+ }
4225
+ }
4226
+
4227
+ function checkIntBI (value, min, max, buf, offset, byteLength) {
4228
+ if (value > max || value < min) {
4229
+ const n = typeof min === 'bigint' ? 'n' : '';
4230
+ let range;
4231
+ {
4232
+ if (min === 0 || min === BigInt(0)) {
4233
+ range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`;
4234
+ } else {
4235
+ range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
4236
+ `${(byteLength + 1) * 8 - 1}${n}`;
4237
+ }
4238
+ }
4239
+ throw new errors.ERR_OUT_OF_RANGE('value', range, value)
4240
+ }
4241
+ checkBounds(buf, offset, byteLength);
4242
+ }
4243
+
4244
+ function validateNumber (value, name) {
4245
+ if (typeof value !== 'number') {
4246
+ throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value)
4247
+ }
4248
+ }
4249
+
4250
+ function boundsError (value, length, type) {
4251
+ if (Math.floor(value) !== value) {
4252
+ validateNumber(value, type);
4253
+ throw new errors.ERR_OUT_OF_RANGE('offset', 'an integer', value)
4254
+ }
4255
+
4256
+ if (length < 0) {
4257
+ throw new errors.ERR_BUFFER_OUT_OF_BOUNDS()
4258
+ }
4259
+
4260
+ throw new errors.ERR_OUT_OF_RANGE('offset',
4261
+ `>= ${0} and <= ${length}`,
4262
+ value)
4263
+ }
4264
+
4265
+ // HELPER FUNCTIONS
4266
+ // ================
4267
+
4268
+ const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
4269
+
4270
+ function base64clean (str) {
4271
+ // Node takes equal signs as end of the Base64 encoding
4272
+ str = str.split('=')[0];
4273
+ // Node strips out invalid characters like \n and \t from the string, base64-js does not
4274
+ str = str.trim().replace(INVALID_BASE64_RE, '');
4275
+ // Node converts strings with length < 2 to ''
4276
+ if (str.length < 2) return ''
4277
+ // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
4278
+ while (str.length % 4 !== 0) {
4279
+ str = str + '=';
4280
+ }
4281
+ return str
4282
+ }
4283
+
4284
+ function utf8ToBytes (string, units) {
4285
+ units = units || Infinity;
4286
+ let codePoint;
4287
+ const length = string.length;
4288
+ let leadSurrogate = null;
4289
+ const bytes = [];
4290
+
4291
+ for (let i = 0; i < length; ++i) {
4292
+ codePoint = string.charCodeAt(i);
4293
+
4294
+ // is surrogate component
4295
+ if (codePoint > 0xD7FF && codePoint < 0xE000) {
4296
+ // last char was a lead
4297
+ if (!leadSurrogate) {
4298
+ // no lead yet
4299
+ if (codePoint > 0xDBFF) {
4300
+ // unexpected trail
4301
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
4302
+ continue
4303
+ } else if (i + 1 === length) {
4304
+ // unpaired lead
4305
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
4306
+ continue
4307
+ }
4308
+
4309
+ // valid lead
4310
+ leadSurrogate = codePoint;
4311
+
4312
+ continue
4313
+ }
4314
+
4315
+ // 2 leads in a row
4316
+ if (codePoint < 0xDC00) {
4317
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
4318
+ leadSurrogate = codePoint;
4319
+ continue
4320
+ }
4321
+
4322
+ // valid surrogate pair
4323
+ codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
4324
+ } else if (leadSurrogate) {
4325
+ // valid bmp char, but last char was a lead
4326
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
4327
+ }
4328
+
4329
+ leadSurrogate = null;
4330
+
4331
+ // encode utf8
4332
+ if (codePoint < 0x80) {
4333
+ if ((units -= 1) < 0) break
4334
+ bytes.push(codePoint);
4335
+ } else if (codePoint < 0x800) {
4336
+ if ((units -= 2) < 0) break
4337
+ bytes.push(
4338
+ codePoint >> 0x6 | 0xC0,
4339
+ codePoint & 0x3F | 0x80
4340
+ );
4341
+ } else if (codePoint < 0x10000) {
4342
+ if ((units -= 3) < 0) break
4343
+ bytes.push(
4344
+ codePoint >> 0xC | 0xE0,
4345
+ codePoint >> 0x6 & 0x3F | 0x80,
4346
+ codePoint & 0x3F | 0x80
4347
+ );
4348
+ } else if (codePoint < 0x110000) {
4349
+ if ((units -= 4) < 0) break
4350
+ bytes.push(
4351
+ codePoint >> 0x12 | 0xF0,
4352
+ codePoint >> 0xC & 0x3F | 0x80,
4353
+ codePoint >> 0x6 & 0x3F | 0x80,
4354
+ codePoint & 0x3F | 0x80
4355
+ );
4356
+ } else {
4357
+ throw new Error('Invalid code point')
4358
+ }
4359
+ }
4360
+
4361
+ return bytes
4362
+ }
4363
+
4364
+ function asciiToBytes (str) {
4365
+ const byteArray = [];
4366
+ for (let i = 0; i < str.length; ++i) {
4367
+ // Node's code seems to be doing this and not & 0x7F..
4368
+ byteArray.push(str.charCodeAt(i) & 0xFF);
4369
+ }
4370
+ return byteArray
4371
+ }
4372
+
4373
+ function utf16leToBytes (str, units) {
4374
+ let c, hi, lo;
4375
+ const byteArray = [];
4376
+ for (let i = 0; i < str.length; ++i) {
4377
+ if ((units -= 2) < 0) break
4378
+
4379
+ c = str.charCodeAt(i);
4380
+ hi = c >> 8;
4381
+ lo = c % 256;
4382
+ byteArray.push(lo);
4383
+ byteArray.push(hi);
4384
+ }
4385
+
4386
+ return byteArray
4387
+ }
4388
+
4389
+ function base64ToBytes (str) {
4390
+ return base64.toByteArray(base64clean(str))
4391
+ }
4392
+
4393
+ function blitBuffer (src, dst, offset, length) {
4394
+ let i;
4395
+ for (i = 0; i < length; ++i) {
4396
+ if ((i + offset >= dst.length) || (i >= src.length)) break
4397
+ dst[i + offset] = src[i];
4398
+ }
4399
+ return i
4400
+ }
4401
+
4402
+ // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
4403
+ // the `instanceof` check but they should be treated as of that type.
4404
+ // See: https://github.com/feross/buffer/issues/166
4405
+ function isInstance (obj, type) {
4406
+ return obj instanceof type ||
4407
+ (obj != null && obj.constructor != null && obj.constructor.name != null &&
4408
+ obj.constructor.name === type.name)
4409
+ }
4410
+ function numberIsNaN (obj) {
4411
+ // For IE11 support
4412
+ return obj !== obj // eslint-disable-line no-self-compare
4413
+ }
4414
+
4415
+ // Create lookup table for `toString('hex')`
4416
+ // See: https://github.com/feross/buffer/issues/219
4417
+ const hexSliceLookupTable = (function () {
4418
+ const alphabet = '0123456789abcdef';
4419
+ const table = new Array(256);
4420
+ for (let i = 0; i < 16; ++i) {
4421
+ const i16 = i * 16;
4422
+ for (let j = 0; j < 16; ++j) {
4423
+ table[i16 + j] = alphabet[i] + alphabet[j];
4424
+ }
4425
+ }
4426
+ return table
4427
+ })();
4428
+
4429
+ // Return not function with Error if BigInt not supported
4430
+ function defineBigIntMethod (fn) {
4431
+ return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn
4432
+ }
4433
+
4434
+ function BufferBigIntNotDefined () {
4435
+ throw new Error('BigInt not supported')
4436
+ }
4437
+ } (buffer$1));
4438
+ return buffer$1;
4439
+ }
4440
+
4441
+ var bufferExports$1 = requireBuffer$1();
4442
+
4443
+ var dist = {};
4444
+
4445
+ var buffer = {};
4446
+
4447
+ /*!
4448
+ * The buffer module from node.js, for the browser.
4449
+ *
4450
+ * @author Feross Aboukhadijeh <https://feross.org>
4451
+ * @license MIT
4452
+ */
4453
+
4454
+ var hasRequiredBuffer;
4455
+
4456
+ function requireBuffer () {
4457
+ if (hasRequiredBuffer) return buffer;
4458
+ hasRequiredBuffer = 1;
4459
+ (function (exports) {
4460
+
4461
+ var base64 = requireBase64Js();
4462
+ var ieee754 = requireIeee754();
4463
+ var customInspectSymbol =
4464
+ (typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation
4465
+ ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
4466
+ : null;
4467
+
4468
+ exports.Buffer = Buffer;
4469
+ exports.SlowBuffer = SlowBuffer;
4470
+ exports.INSPECT_MAX_BYTES = 50;
4471
+
4472
+ var K_MAX_LENGTH = 0x7fffffff;
4473
+ exports.kMaxLength = K_MAX_LENGTH;
4474
+
4475
+ /**
4476
+ * If `Buffer.TYPED_ARRAY_SUPPORT`:
4477
+ * === true Use Uint8Array implementation (fastest)
4478
+ * === false Print warning and recommend using `buffer` v4.x which has an Object
4479
+ * implementation (most compatible, even IE6)
4480
+ *
4481
+ * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
4482
+ * Opera 11.6+, iOS 4.2+.
4483
+ *
4484
+ * We report that the browser does not support typed arrays if the are not subclassable
4485
+ * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
4486
+ * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
4487
+ * for __proto__ and has a buggy typed array implementation.
4488
+ */
4489
+ Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
4490
+
4491
+ if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
4492
+ typeof console.error === 'function') {
4493
+ console.error(
4494
+ 'This browser lacks typed array (Uint8Array) support which is required by ' +
4495
+ '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
4496
+ );
4497
+ }
4498
+
4499
+ function typedArraySupport () {
4500
+ // Can typed array instances can be augmented?
4501
+ try {
4502
+ var arr = new Uint8Array(1);
4503
+ var proto = { foo: function () { return 42 } };
4504
+ Object.setPrototypeOf(proto, Uint8Array.prototype);
4505
+ Object.setPrototypeOf(arr, proto);
4506
+ return arr.foo() === 42
4507
+ } catch (e) {
4508
+ return false
4509
+ }
4510
+ }
4511
+
4512
+ Object.defineProperty(Buffer.prototype, 'parent', {
4513
+ enumerable: true,
4514
+ get: function () {
4515
+ if (!Buffer.isBuffer(this)) return undefined
4516
+ return this.buffer
4517
+ }
4518
+ });
4519
+
4520
+ Object.defineProperty(Buffer.prototype, 'offset', {
4521
+ enumerable: true,
4522
+ get: function () {
4523
+ if (!Buffer.isBuffer(this)) return undefined
4524
+ return this.byteOffset
4525
+ }
4526
+ });
4527
+
4528
+ function createBuffer (length) {
4529
+ if (length > K_MAX_LENGTH) {
4530
+ throw new RangeError('The value "' + length + '" is invalid for option "size"')
4531
+ }
4532
+ // Return an augmented `Uint8Array` instance
4533
+ var buf = new Uint8Array(length);
4534
+ Object.setPrototypeOf(buf, Buffer.prototype);
4535
+ return buf
4536
+ }
4537
+
4538
+ /**
4539
+ * The Buffer constructor returns instances of `Uint8Array` that have their
4540
+ * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
4541
+ * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
4542
+ * and the `Uint8Array` methods. Square bracket notation works as expected -- it
4543
+ * returns a single octet.
4544
+ *
4545
+ * The `Uint8Array` prototype remains unmodified.
4546
+ */
4547
+
4548
+ function Buffer (arg, encodingOrOffset, length) {
4549
+ // Common case.
4550
+ if (typeof arg === 'number') {
4551
+ if (typeof encodingOrOffset === 'string') {
4552
+ throw new TypeError(
4553
+ 'The "string" argument must be of type string. Received type number'
4554
+ )
4555
+ }
4556
+ return allocUnsafe(arg)
4557
+ }
4558
+ return from(arg, encodingOrOffset, length)
4559
+ }
4560
+
4561
+ Buffer.poolSize = 8192; // not used by this implementation
4562
+
4563
+ function from (value, encodingOrOffset, length) {
4564
+ if (typeof value === 'string') {
4565
+ return fromString(value, encodingOrOffset)
4566
+ }
4567
+
4568
+ if (ArrayBuffer.isView(value)) {
4569
+ return fromArrayView(value)
4570
+ }
4571
+
4572
+ if (value == null) {
4573
+ throw new TypeError(
4574
+ 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
4575
+ 'or Array-like Object. Received type ' + (typeof value)
4576
+ )
4577
+ }
4578
+
4579
+ if (isInstance(value, ArrayBuffer) ||
4580
+ (value && isInstance(value.buffer, ArrayBuffer))) {
4581
+ return fromArrayBuffer(value, encodingOrOffset, length)
4582
+ }
4583
+
4584
+ if (typeof SharedArrayBuffer !== 'undefined' &&
4585
+ (isInstance(value, SharedArrayBuffer) ||
4586
+ (value && isInstance(value.buffer, SharedArrayBuffer)))) {
4587
+ return fromArrayBuffer(value, encodingOrOffset, length)
4588
+ }
4589
+
4590
+ if (typeof value === 'number') {
4591
+ throw new TypeError(
4592
+ 'The "value" argument must not be of type number. Received type number'
4593
+ )
4594
+ }
4595
+
4596
+ var valueOf = value.valueOf && value.valueOf();
4597
+ if (valueOf != null && valueOf !== value) {
4598
+ return Buffer.from(valueOf, encodingOrOffset, length)
4599
+ }
4600
+
4601
+ var b = fromObject(value);
4602
+ if (b) return b
4603
+
4604
+ if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
4605
+ typeof value[Symbol.toPrimitive] === 'function') {
4606
+ return Buffer.from(
4607
+ value[Symbol.toPrimitive]('string'), encodingOrOffset, length
4608
+ )
4609
+ }
4610
+
4611
+ throw new TypeError(
4612
+ 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
4613
+ 'or Array-like Object. Received type ' + (typeof value)
4614
+ )
4615
+ }
4616
+
4617
+ /**
4618
+ * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
4619
+ * if value is a number.
4620
+ * Buffer.from(str[, encoding])
4621
+ * Buffer.from(array)
4622
+ * Buffer.from(buffer)
4623
+ * Buffer.from(arrayBuffer[, byteOffset[, length]])
4624
+ **/
4625
+ Buffer.from = function (value, encodingOrOffset, length) {
4626
+ return from(value, encodingOrOffset, length)
4627
+ };
4628
+
4629
+ // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
4630
+ // https://github.com/feross/buffer/pull/148
4631
+ Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
4632
+ Object.setPrototypeOf(Buffer, Uint8Array);
4633
+
4634
+ function assertSize (size) {
4635
+ if (typeof size !== 'number') {
4636
+ throw new TypeError('"size" argument must be of type number')
4637
+ } else if (size < 0) {
4638
+ throw new RangeError('The value "' + size + '" is invalid for option "size"')
4639
+ }
4640
+ }
4641
+
4642
+ function alloc (size, fill, encoding) {
4643
+ assertSize(size);
4644
+ if (size <= 0) {
4645
+ return createBuffer(size)
4646
+ }
4647
+ if (fill !== undefined) {
4648
+ // Only pay attention to encoding if it's a string. This
4649
+ // prevents accidentally sending in a number that would
4650
+ // be interpreted as a start offset.
4651
+ return typeof encoding === 'string'
4652
+ ? createBuffer(size).fill(fill, encoding)
4653
+ : createBuffer(size).fill(fill)
4654
+ }
4655
+ return createBuffer(size)
4656
+ }
4657
+
4658
+ /**
4659
+ * Creates a new filled Buffer instance.
4660
+ * alloc(size[, fill[, encoding]])
4661
+ **/
4662
+ Buffer.alloc = function (size, fill, encoding) {
4663
+ return alloc(size, fill, encoding)
4664
+ };
4665
+
4666
+ function allocUnsafe (size) {
4667
+ assertSize(size);
4668
+ return createBuffer(size < 0 ? 0 : checked(size) | 0)
4669
+ }
4670
+
4671
+ /**
4672
+ * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
4673
+ * */
4674
+ Buffer.allocUnsafe = function (size) {
4675
+ return allocUnsafe(size)
4676
+ };
4677
+ /**
4678
+ * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
4679
+ */
4680
+ Buffer.allocUnsafeSlow = function (size) {
4681
+ return allocUnsafe(size)
4682
+ };
4683
+
4684
+ function fromString (string, encoding) {
4685
+ if (typeof encoding !== 'string' || encoding === '') {
4686
+ encoding = 'utf8';
4687
+ }
4688
+
4689
+ if (!Buffer.isEncoding(encoding)) {
4690
+ throw new TypeError('Unknown encoding: ' + encoding)
4691
+ }
4692
+
4693
+ var length = byteLength(string, encoding) | 0;
4694
+ var buf = createBuffer(length);
4695
+
4696
+ var actual = buf.write(string, encoding);
4697
+
4698
+ if (actual !== length) {
4699
+ // Writing a hex string, for example, that contains invalid characters will
4700
+ // cause everything after the first invalid character to be ignored. (e.g.
4701
+ // 'abxxcd' will be treated as 'ab')
4702
+ buf = buf.slice(0, actual);
4703
+ }
4704
+
4705
+ return buf
4706
+ }
4707
+
4708
+ function fromArrayLike (array) {
4709
+ var length = array.length < 0 ? 0 : checked(array.length) | 0;
4710
+ var buf = createBuffer(length);
4711
+ for (var i = 0; i < length; i += 1) {
4712
+ buf[i] = array[i] & 255;
4713
+ }
4714
+ return buf
4715
+ }
4716
+
4717
+ function fromArrayView (arrayView) {
4718
+ if (isInstance(arrayView, Uint8Array)) {
4719
+ var copy = new Uint8Array(arrayView);
4720
+ return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)
4721
+ }
4722
+ return fromArrayLike(arrayView)
4723
+ }
4724
+
4725
+ function fromArrayBuffer (array, byteOffset, length) {
4726
+ if (byteOffset < 0 || array.byteLength < byteOffset) {
4727
+ throw new RangeError('"offset" is outside of buffer bounds')
4728
+ }
4729
+
4730
+ if (array.byteLength < byteOffset + (length || 0)) {
4731
+ throw new RangeError('"length" is outside of buffer bounds')
4732
+ }
4733
+
4734
+ var buf;
4735
+ if (byteOffset === undefined && length === undefined) {
4736
+ buf = new Uint8Array(array);
4737
+ } else if (length === undefined) {
4738
+ buf = new Uint8Array(array, byteOffset);
4739
+ } else {
4740
+ buf = new Uint8Array(array, byteOffset, length);
4741
+ }
4742
+
4743
+ // Return an augmented `Uint8Array` instance
4744
+ Object.setPrototypeOf(buf, Buffer.prototype);
4745
+
4746
+ return buf
4747
+ }
4748
+
4749
+ function fromObject (obj) {
4750
+ if (Buffer.isBuffer(obj)) {
4751
+ var len = checked(obj.length) | 0;
4752
+ var buf = createBuffer(len);
4753
+
4754
+ if (buf.length === 0) {
4755
+ return buf
4756
+ }
4757
+
4758
+ obj.copy(buf, 0, 0, len);
4759
+ return buf
4760
+ }
4761
+
4762
+ if (obj.length !== undefined) {
4763
+ if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
4764
+ return createBuffer(0)
4765
+ }
4766
+ return fromArrayLike(obj)
4767
+ }
4768
+
4769
+ if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
4770
+ return fromArrayLike(obj.data)
4771
+ }
4772
+ }
4773
+
4774
+ function checked (length) {
4775
+ // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
4776
+ // length is NaN (which is otherwise coerced to zero.)
4777
+ if (length >= K_MAX_LENGTH) {
4778
+ throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
4779
+ 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
4780
+ }
4781
+ return length | 0
4782
+ }
4783
+
4784
+ function SlowBuffer (length) {
4785
+ if (+length != length) { // eslint-disable-line eqeqeq
4786
+ length = 0;
4787
+ }
4788
+ return Buffer.alloc(+length)
4789
+ }
4790
+
4791
+ Buffer.isBuffer = function isBuffer (b) {
4792
+ return b != null && b._isBuffer === true &&
4793
+ b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
4794
+ };
4795
+
4796
+ Buffer.compare = function compare (a, b) {
4797
+ if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);
4798
+ if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);
4799
+ if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
4800
+ throw new TypeError(
4801
+ 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
4802
+ )
4803
+ }
4804
+
4805
+ if (a === b) return 0
4806
+
4807
+ var x = a.length;
4808
+ var y = b.length;
4809
+
4810
+ for (var i = 0, len = Math.min(x, y); i < len; ++i) {
4811
+ if (a[i] !== b[i]) {
4812
+ x = a[i];
4813
+ y = b[i];
4814
+ break
4815
+ }
4816
+ }
4817
+
4818
+ if (x < y) return -1
4819
+ if (y < x) return 1
4820
+ return 0
4821
+ };
4822
+
4823
+ Buffer.isEncoding = function isEncoding (encoding) {
4824
+ switch (String(encoding).toLowerCase()) {
4825
+ case 'hex':
4826
+ case 'utf8':
4827
+ case 'utf-8':
4828
+ case 'ascii':
4829
+ case 'latin1':
4830
+ case 'binary':
4831
+ case 'base64':
4832
+ case 'ucs2':
4833
+ case 'ucs-2':
4834
+ case 'utf16le':
4835
+ case 'utf-16le':
4836
+ return true
4837
+ default:
4838
+ return false
4839
+ }
4840
+ };
4841
+
4842
+ Buffer.concat = function concat (list, length) {
4843
+ if (!Array.isArray(list)) {
4844
+ throw new TypeError('"list" argument must be an Array of Buffers')
4845
+ }
4846
+
4847
+ if (list.length === 0) {
4848
+ return Buffer.alloc(0)
4849
+ }
4850
+
4851
+ var i;
4852
+ if (length === undefined) {
4853
+ length = 0;
4854
+ for (i = 0; i < list.length; ++i) {
4855
+ length += list[i].length;
4856
+ }
4857
+ }
4858
+
4859
+ var buffer = Buffer.allocUnsafe(length);
4860
+ var pos = 0;
4861
+ for (i = 0; i < list.length; ++i) {
4862
+ var buf = list[i];
4863
+ if (isInstance(buf, Uint8Array)) {
4864
+ if (pos + buf.length > buffer.length) {
4865
+ Buffer.from(buf).copy(buffer, pos);
4866
+ } else {
4867
+ Uint8Array.prototype.set.call(
4868
+ buffer,
4869
+ buf,
4870
+ pos
4871
+ );
4872
+ }
4873
+ } else if (!Buffer.isBuffer(buf)) {
4874
+ throw new TypeError('"list" argument must be an Array of Buffers')
4875
+ } else {
4876
+ buf.copy(buffer, pos);
4877
+ }
4878
+ pos += buf.length;
4879
+ }
4880
+ return buffer
4881
+ };
4882
+
4883
+ function byteLength (string, encoding) {
4884
+ if (Buffer.isBuffer(string)) {
4885
+ return string.length
4886
+ }
4887
+ if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
4888
+ return string.byteLength
4889
+ }
4890
+ if (typeof string !== 'string') {
4891
+ throw new TypeError(
4892
+ 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
4893
+ 'Received type ' + typeof string
4894
+ )
4895
+ }
4896
+
4897
+ var len = string.length;
4898
+ var mustMatch = (arguments.length > 2 && arguments[2] === true);
4899
+ if (!mustMatch && len === 0) return 0
4900
+
4901
+ // Use a for loop to avoid recursion
4902
+ var loweredCase = false;
4903
+ for (;;) {
4904
+ switch (encoding) {
4905
+ case 'ascii':
4906
+ case 'latin1':
4907
+ case 'binary':
4908
+ return len
4909
+ case 'utf8':
4910
+ case 'utf-8':
4911
+ return utf8ToBytes(string).length
4912
+ case 'ucs2':
4913
+ case 'ucs-2':
4914
+ case 'utf16le':
4915
+ case 'utf-16le':
4916
+ return len * 2
4917
+ case 'hex':
4918
+ return len >>> 1
4919
+ case 'base64':
4920
+ return base64ToBytes(string).length
4921
+ default:
4922
+ if (loweredCase) {
4923
+ return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
4924
+ }
4925
+ encoding = ('' + encoding).toLowerCase();
4926
+ loweredCase = true;
4927
+ }
4928
+ }
4929
+ }
4930
+ Buffer.byteLength = byteLength;
4931
+
4932
+ function slowToString (encoding, start, end) {
4933
+ var loweredCase = false;
4934
+
4935
+ // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
4936
+ // property of a typed array.
4937
+
4938
+ // This behaves neither like String nor Uint8Array in that we set start/end
4939
+ // to their upper/lower bounds if the value passed is out of range.
4940
+ // undefined is handled specially as per ECMA-262 6th Edition,
4941
+ // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
4942
+ if (start === undefined || start < 0) {
4943
+ start = 0;
4944
+ }
4945
+ // Return early if start > this.length. Done here to prevent potential uint32
4946
+ // coercion fail below.
4947
+ if (start > this.length) {
4948
+ return ''
4949
+ }
4950
+
4951
+ if (end === undefined || end > this.length) {
4952
+ end = this.length;
4953
+ }
4954
+
4955
+ if (end <= 0) {
4956
+ return ''
4957
+ }
4958
+
4959
+ // Force coercion to uint32. This will also coerce falsey/NaN values to 0.
4960
+ end >>>= 0;
4961
+ start >>>= 0;
4962
+
4963
+ if (end <= start) {
4964
+ return ''
4965
+ }
4966
+
4967
+ if (!encoding) encoding = 'utf8';
4968
+
4969
+ while (true) {
4970
+ switch (encoding) {
4971
+ case 'hex':
4972
+ return hexSlice(this, start, end)
4973
+
4974
+ case 'utf8':
4975
+ case 'utf-8':
4976
+ return utf8Slice(this, start, end)
4977
+
4978
+ case 'ascii':
4979
+ return asciiSlice(this, start, end)
4980
+
4981
+ case 'latin1':
4982
+ case 'binary':
4983
+ return latin1Slice(this, start, end)
4984
+
4985
+ case 'base64':
4986
+ return base64Slice(this, start, end)
4987
+
4988
+ case 'ucs2':
4989
+ case 'ucs-2':
4990
+ case 'utf16le':
4991
+ case 'utf-16le':
4992
+ return utf16leSlice(this, start, end)
4993
+
4994
+ default:
4995
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
4996
+ encoding = (encoding + '').toLowerCase();
4997
+ loweredCase = true;
4998
+ }
4999
+ }
5000
+ }
5001
+
5002
+ // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
5003
+ // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
5004
+ // reliably in a browserify context because there could be multiple different
5005
+ // copies of the 'buffer' package in use. This method works even for Buffer
5006
+ // instances that were created from another copy of the `buffer` package.
5007
+ // See: https://github.com/feross/buffer/issues/154
5008
+ Buffer.prototype._isBuffer = true;
5009
+
5010
+ function swap (b, n, m) {
5011
+ var i = b[n];
5012
+ b[n] = b[m];
5013
+ b[m] = i;
5014
+ }
5015
+
5016
+ Buffer.prototype.swap16 = function swap16 () {
5017
+ var len = this.length;
5018
+ if (len % 2 !== 0) {
5019
+ throw new RangeError('Buffer size must be a multiple of 16-bits')
5020
+ }
5021
+ for (var i = 0; i < len; i += 2) {
5022
+ swap(this, i, i + 1);
5023
+ }
5024
+ return this
5025
+ };
5026
+
5027
+ Buffer.prototype.swap32 = function swap32 () {
5028
+ var len = this.length;
5029
+ if (len % 4 !== 0) {
5030
+ throw new RangeError('Buffer size must be a multiple of 32-bits')
5031
+ }
5032
+ for (var i = 0; i < len; i += 4) {
5033
+ swap(this, i, i + 3);
5034
+ swap(this, i + 1, i + 2);
5035
+ }
5036
+ return this
5037
+ };
5038
+
5039
+ Buffer.prototype.swap64 = function swap64 () {
5040
+ var len = this.length;
5041
+ if (len % 8 !== 0) {
5042
+ throw new RangeError('Buffer size must be a multiple of 64-bits')
5043
+ }
5044
+ for (var i = 0; i < len; i += 8) {
5045
+ swap(this, i, i + 7);
5046
+ swap(this, i + 1, i + 6);
5047
+ swap(this, i + 2, i + 5);
5048
+ swap(this, i + 3, i + 4);
5049
+ }
5050
+ return this
5051
+ };
5052
+
5053
+ Buffer.prototype.toString = function toString () {
5054
+ var length = this.length;
5055
+ if (length === 0) return ''
5056
+ if (arguments.length === 0) return utf8Slice(this, 0, length)
5057
+ return slowToString.apply(this, arguments)
5058
+ };
5059
+
5060
+ Buffer.prototype.toLocaleString = Buffer.prototype.toString;
5061
+
5062
+ Buffer.prototype.equals = function equals (b) {
5063
+ if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
5064
+ if (this === b) return true
5065
+ return Buffer.compare(this, b) === 0
5066
+ };
5067
+
5068
+ Buffer.prototype.inspect = function inspect () {
5069
+ var str = '';
5070
+ var max = exports.INSPECT_MAX_BYTES;
5071
+ str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
5072
+ if (this.length > max) str += ' ... ';
5073
+ return '<Buffer ' + str + '>'
5074
+ };
5075
+ if (customInspectSymbol) {
5076
+ Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
5077
+ }
5078
+
5079
+ Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
5080
+ if (isInstance(target, Uint8Array)) {
5081
+ target = Buffer.from(target, target.offset, target.byteLength);
5082
+ }
5083
+ if (!Buffer.isBuffer(target)) {
5084
+ throw new TypeError(
5085
+ 'The "target" argument must be one of type Buffer or Uint8Array. ' +
5086
+ 'Received type ' + (typeof target)
5087
+ )
5088
+ }
5089
+
5090
+ if (start === undefined) {
5091
+ start = 0;
5092
+ }
5093
+ if (end === undefined) {
5094
+ end = target ? target.length : 0;
5095
+ }
5096
+ if (thisStart === undefined) {
5097
+ thisStart = 0;
5098
+ }
5099
+ if (thisEnd === undefined) {
5100
+ thisEnd = this.length;
5101
+ }
5102
+
5103
+ if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
5104
+ throw new RangeError('out of range index')
5105
+ }
5106
+
5107
+ if (thisStart >= thisEnd && start >= end) {
5108
+ return 0
5109
+ }
5110
+ if (thisStart >= thisEnd) {
5111
+ return -1
5112
+ }
5113
+ if (start >= end) {
5114
+ return 1
5115
+ }
5116
+
5117
+ start >>>= 0;
5118
+ end >>>= 0;
5119
+ thisStart >>>= 0;
5120
+ thisEnd >>>= 0;
5121
+
5122
+ if (this === target) return 0
5123
+
5124
+ var x = thisEnd - thisStart;
5125
+ var y = end - start;
5126
+ var len = Math.min(x, y);
5127
+
5128
+ var thisCopy = this.slice(thisStart, thisEnd);
5129
+ var targetCopy = target.slice(start, end);
5130
+
5131
+ for (var i = 0; i < len; ++i) {
5132
+ if (thisCopy[i] !== targetCopy[i]) {
5133
+ x = thisCopy[i];
5134
+ y = targetCopy[i];
5135
+ break
5136
+ }
5137
+ }
5138
+
5139
+ if (x < y) return -1
5140
+ if (y < x) return 1
5141
+ return 0
5142
+ };
5143
+
5144
+ // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
5145
+ // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
5146
+ //
5147
+ // Arguments:
5148
+ // - buffer - a Buffer to search
5149
+ // - val - a string, Buffer, or number
5150
+ // - byteOffset - an index into `buffer`; will be clamped to an int32
5151
+ // - encoding - an optional encoding, relevant is val is a string
5152
+ // - dir - true for indexOf, false for lastIndexOf
5153
+ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
5154
+ // Empty buffer means no match
5155
+ if (buffer.length === 0) return -1
5156
+
5157
+ // Normalize byteOffset
5158
+ if (typeof byteOffset === 'string') {
5159
+ encoding = byteOffset;
5160
+ byteOffset = 0;
5161
+ } else if (byteOffset > 0x7fffffff) {
5162
+ byteOffset = 0x7fffffff;
5163
+ } else if (byteOffset < -2147483648) {
5164
+ byteOffset = -2147483648;
5165
+ }
5166
+ byteOffset = +byteOffset; // Coerce to Number.
5167
+ if (numberIsNaN(byteOffset)) {
5168
+ // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
5169
+ byteOffset = dir ? 0 : (buffer.length - 1);
5170
+ }
5171
+
5172
+ // Normalize byteOffset: negative offsets start from the end of the buffer
5173
+ if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
5174
+ if (byteOffset >= buffer.length) {
5175
+ if (dir) return -1
5176
+ else byteOffset = buffer.length - 1;
5177
+ } else if (byteOffset < 0) {
5178
+ if (dir) byteOffset = 0;
5179
+ else return -1
5180
+ }
5181
+
5182
+ // Normalize val
5183
+ if (typeof val === 'string') {
5184
+ val = Buffer.from(val, encoding);
5185
+ }
5186
+
5187
+ // Finally, search either indexOf (if dir is true) or lastIndexOf
5188
+ if (Buffer.isBuffer(val)) {
5189
+ // Special case: looking for empty string/buffer always fails
5190
+ if (val.length === 0) {
5191
+ return -1
5192
+ }
5193
+ return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
5194
+ } else if (typeof val === 'number') {
5195
+ val = val & 0xFF; // Search for a byte value [0-255]
5196
+ if (typeof Uint8Array.prototype.indexOf === 'function') {
5197
+ if (dir) {
5198
+ return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
5199
+ } else {
5200
+ return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
5201
+ }
5202
+ }
5203
+ return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
5204
+ }
5205
+
5206
+ throw new TypeError('val must be string, number or Buffer')
5207
+ }
5208
+
5209
+ function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
5210
+ var indexSize = 1;
5211
+ var arrLength = arr.length;
5212
+ var valLength = val.length;
5213
+
5214
+ if (encoding !== undefined) {
5215
+ encoding = String(encoding).toLowerCase();
5216
+ if (encoding === 'ucs2' || encoding === 'ucs-2' ||
5217
+ encoding === 'utf16le' || encoding === 'utf-16le') {
5218
+ if (arr.length < 2 || val.length < 2) {
5219
+ return -1
5220
+ }
5221
+ indexSize = 2;
5222
+ arrLength /= 2;
5223
+ valLength /= 2;
5224
+ byteOffset /= 2;
5225
+ }
5226
+ }
5227
+
5228
+ function read (buf, i) {
5229
+ if (indexSize === 1) {
5230
+ return buf[i]
5231
+ } else {
5232
+ return buf.readUInt16BE(i * indexSize)
5233
+ }
5234
+ }
5235
+
5236
+ var i;
5237
+ if (dir) {
5238
+ var foundIndex = -1;
5239
+ for (i = byteOffset; i < arrLength; i++) {
5240
+ if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
5241
+ if (foundIndex === -1) foundIndex = i;
5242
+ if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
5243
+ } else {
5244
+ if (foundIndex !== -1) i -= i - foundIndex;
5245
+ foundIndex = -1;
5246
+ }
5247
+ }
5248
+ } else {
5249
+ if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
5250
+ for (i = byteOffset; i >= 0; i--) {
5251
+ var found = true;
5252
+ for (var j = 0; j < valLength; j++) {
5253
+ if (read(arr, i + j) !== read(val, j)) {
5254
+ found = false;
5255
+ break
5256
+ }
5257
+ }
5258
+ if (found) return i
5259
+ }
5260
+ }
5261
+
5262
+ return -1
5263
+ }
5264
+
5265
+ Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
5266
+ return this.indexOf(val, byteOffset, encoding) !== -1
5267
+ };
5268
+
5269
+ Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
5270
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
5271
+ };
5272
+
5273
+ Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
5274
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
5275
+ };
5276
+
5277
+ function hexWrite (buf, string, offset, length) {
5278
+ offset = Number(offset) || 0;
5279
+ var remaining = buf.length - offset;
5280
+ if (!length) {
5281
+ length = remaining;
5282
+ } else {
5283
+ length = Number(length);
5284
+ if (length > remaining) {
5285
+ length = remaining;
5286
+ }
5287
+ }
5288
+
5289
+ var strLen = string.length;
5290
+
5291
+ if (length > strLen / 2) {
5292
+ length = strLen / 2;
5293
+ }
5294
+ for (var i = 0; i < length; ++i) {
5295
+ var parsed = parseInt(string.substr(i * 2, 2), 16);
5296
+ if (numberIsNaN(parsed)) return i
5297
+ buf[offset + i] = parsed;
5298
+ }
5299
+ return i
5300
+ }
5301
+
5302
+ function utf8Write (buf, string, offset, length) {
5303
+ return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
5304
+ }
5305
+
5306
+ function asciiWrite (buf, string, offset, length) {
5307
+ return blitBuffer(asciiToBytes(string), buf, offset, length)
5308
+ }
5309
+
5310
+ function base64Write (buf, string, offset, length) {
5311
+ return blitBuffer(base64ToBytes(string), buf, offset, length)
5312
+ }
5313
+
5314
+ function ucs2Write (buf, string, offset, length) {
5315
+ return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
5316
+ }
5317
+
5318
+ Buffer.prototype.write = function write (string, offset, length, encoding) {
5319
+ // Buffer#write(string)
5320
+ if (offset === undefined) {
5321
+ encoding = 'utf8';
5322
+ length = this.length;
5323
+ offset = 0;
5324
+ // Buffer#write(string, encoding)
5325
+ } else if (length === undefined && typeof offset === 'string') {
5326
+ encoding = offset;
5327
+ length = this.length;
5328
+ offset = 0;
5329
+ // Buffer#write(string, offset[, length][, encoding])
5330
+ } else if (isFinite(offset)) {
5331
+ offset = offset >>> 0;
5332
+ if (isFinite(length)) {
5333
+ length = length >>> 0;
5334
+ if (encoding === undefined) encoding = 'utf8';
5335
+ } else {
5336
+ encoding = length;
5337
+ length = undefined;
5338
+ }
5339
+ } else {
5340
+ throw new Error(
5341
+ 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
5342
+ )
5343
+ }
5344
+
5345
+ var remaining = this.length - offset;
5346
+ if (length === undefined || length > remaining) length = remaining;
5347
+
5348
+ if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
5349
+ throw new RangeError('Attempt to write outside buffer bounds')
5350
+ }
5351
+
5352
+ if (!encoding) encoding = 'utf8';
5353
+
5354
+ var loweredCase = false;
5355
+ for (;;) {
5356
+ switch (encoding) {
5357
+ case 'hex':
5358
+ return hexWrite(this, string, offset, length)
5359
+
5360
+ case 'utf8':
5361
+ case 'utf-8':
5362
+ return utf8Write(this, string, offset, length)
5363
+
5364
+ case 'ascii':
5365
+ case 'latin1':
5366
+ case 'binary':
5367
+ return asciiWrite(this, string, offset, length)
5368
+
5369
+ case 'base64':
5370
+ // Warning: maxLength not taken into account in base64Write
5371
+ return base64Write(this, string, offset, length)
5372
+
5373
+ case 'ucs2':
5374
+ case 'ucs-2':
5375
+ case 'utf16le':
5376
+ case 'utf-16le':
5377
+ return ucs2Write(this, string, offset, length)
5378
+
5379
+ default:
5380
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
5381
+ encoding = ('' + encoding).toLowerCase();
5382
+ loweredCase = true;
5383
+ }
5384
+ }
5385
+ };
5386
+
5387
+ Buffer.prototype.toJSON = function toJSON () {
5388
+ return {
5389
+ type: 'Buffer',
5390
+ data: Array.prototype.slice.call(this._arr || this, 0)
5391
+ }
5392
+ };
5393
+
5394
+ function base64Slice (buf, start, end) {
5395
+ if (start === 0 && end === buf.length) {
5396
+ return base64.fromByteArray(buf)
5397
+ } else {
5398
+ return base64.fromByteArray(buf.slice(start, end))
5399
+ }
5400
+ }
5401
+
5402
+ function utf8Slice (buf, start, end) {
5403
+ end = Math.min(buf.length, end);
5404
+ var res = [];
5405
+
5406
+ var i = start;
5407
+ while (i < end) {
5408
+ var firstByte = buf[i];
5409
+ var codePoint = null;
5410
+ var bytesPerSequence = (firstByte > 0xEF)
5411
+ ? 4
5412
+ : (firstByte > 0xDF)
5413
+ ? 3
5414
+ : (firstByte > 0xBF)
5415
+ ? 2
5416
+ : 1;
5417
+
5418
+ if (i + bytesPerSequence <= end) {
5419
+ var secondByte, thirdByte, fourthByte, tempCodePoint;
5420
+
5421
+ switch (bytesPerSequence) {
5422
+ case 1:
5423
+ if (firstByte < 0x80) {
5424
+ codePoint = firstByte;
5425
+ }
5426
+ break
5427
+ case 2:
5428
+ secondByte = buf[i + 1];
5429
+ if ((secondByte & 0xC0) === 0x80) {
5430
+ tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
5431
+ if (tempCodePoint > 0x7F) {
5432
+ codePoint = tempCodePoint;
5433
+ }
5434
+ }
5435
+ break
5436
+ case 3:
5437
+ secondByte = buf[i + 1];
5438
+ thirdByte = buf[i + 2];
5439
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
5440
+ tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
5441
+ if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
5442
+ codePoint = tempCodePoint;
5443
+ }
5444
+ }
5445
+ break
5446
+ case 4:
5447
+ secondByte = buf[i + 1];
5448
+ thirdByte = buf[i + 2];
5449
+ fourthByte = buf[i + 3];
5450
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
5451
+ tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
5452
+ if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
5453
+ codePoint = tempCodePoint;
5454
+ }
5455
+ }
5456
+ }
5457
+ }
5458
+
5459
+ if (codePoint === null) {
5460
+ // we did not generate a valid codePoint so insert a
5461
+ // replacement char (U+FFFD) and advance only 1 byte
5462
+ codePoint = 0xFFFD;
5463
+ bytesPerSequence = 1;
5464
+ } else if (codePoint > 0xFFFF) {
5465
+ // encode to utf16 (surrogate pair dance)
5466
+ codePoint -= 0x10000;
5467
+ res.push(codePoint >>> 10 & 0x3FF | 0xD800);
5468
+ codePoint = 0xDC00 | codePoint & 0x3FF;
5469
+ }
5470
+
5471
+ res.push(codePoint);
5472
+ i += bytesPerSequence;
5473
+ }
5474
+
5475
+ return decodeCodePointsArray(res)
5476
+ }
5477
+
5478
+ // Based on http://stackoverflow.com/a/22747272/680742, the browser with
5479
+ // the lowest limit is Chrome, with 0x10000 args.
5480
+ // We go 1 magnitude less, for safety
5481
+ var MAX_ARGUMENTS_LENGTH = 0x1000;
5482
+
5483
+ function decodeCodePointsArray (codePoints) {
5484
+ var len = codePoints.length;
5485
+ if (len <= MAX_ARGUMENTS_LENGTH) {
5486
+ return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
5487
+ }
5488
+
5489
+ // Decode in chunks to avoid "call stack size exceeded".
5490
+ var res = '';
5491
+ var i = 0;
5492
+ while (i < len) {
5493
+ res += String.fromCharCode.apply(
5494
+ String,
5495
+ codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
5496
+ );
5497
+ }
5498
+ return res
5499
+ }
5500
+
5501
+ function asciiSlice (buf, start, end) {
5502
+ var ret = '';
5503
+ end = Math.min(buf.length, end);
5504
+
5505
+ for (var i = start; i < end; ++i) {
5506
+ ret += String.fromCharCode(buf[i] & 0x7F);
5507
+ }
5508
+ return ret
5509
+ }
5510
+
5511
+ function latin1Slice (buf, start, end) {
5512
+ var ret = '';
5513
+ end = Math.min(buf.length, end);
5514
+
5515
+ for (var i = start; i < end; ++i) {
5516
+ ret += String.fromCharCode(buf[i]);
5517
+ }
5518
+ return ret
5519
+ }
5520
+
5521
+ function hexSlice (buf, start, end) {
5522
+ var len = buf.length;
5523
+
5524
+ if (!start || start < 0) start = 0;
5525
+ if (!end || end < 0 || end > len) end = len;
5526
+
5527
+ var out = '';
5528
+ for (var i = start; i < end; ++i) {
5529
+ out += hexSliceLookupTable[buf[i]];
5530
+ }
5531
+ return out
5532
+ }
5533
+
5534
+ function utf16leSlice (buf, start, end) {
5535
+ var bytes = buf.slice(start, end);
5536
+ var res = '';
5537
+ // If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
5538
+ for (var i = 0; i < bytes.length - 1; i += 2) {
5539
+ res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256));
5540
+ }
5541
+ return res
5542
+ }
5543
+
5544
+ Buffer.prototype.slice = function slice (start, end) {
5545
+ var len = this.length;
5546
+ start = ~~start;
5547
+ end = end === undefined ? len : ~~end;
5548
+
5549
+ if (start < 0) {
5550
+ start += len;
5551
+ if (start < 0) start = 0;
5552
+ } else if (start > len) {
5553
+ start = len;
5554
+ }
5555
+
5556
+ if (end < 0) {
5557
+ end += len;
5558
+ if (end < 0) end = 0;
5559
+ } else if (end > len) {
5560
+ end = len;
5561
+ }
5562
+
5563
+ if (end < start) end = start;
5564
+
5565
+ var newBuf = this.subarray(start, end);
5566
+ // Return an augmented `Uint8Array` instance
5567
+ Object.setPrototypeOf(newBuf, Buffer.prototype);
5568
+
5569
+ return newBuf
5570
+ };
5571
+
5572
+ /*
5573
+ * Need to make sure that buffer isn't trying to write out of bounds.
5574
+ */
5575
+ function checkOffset (offset, ext, length) {
5576
+ if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
5577
+ if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
5578
+ }
5579
+
5580
+ Buffer.prototype.readUintLE =
5581
+ Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
5582
+ offset = offset >>> 0;
5583
+ byteLength = byteLength >>> 0;
5584
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
5585
+
5586
+ var val = this[offset];
5587
+ var mul = 1;
5588
+ var i = 0;
5589
+ while (++i < byteLength && (mul *= 0x100)) {
5590
+ val += this[offset + i] * mul;
5591
+ }
5592
+
5593
+ return val
5594
+ };
5595
+
5596
+ Buffer.prototype.readUintBE =
5597
+ Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
5598
+ offset = offset >>> 0;
5599
+ byteLength = byteLength >>> 0;
5600
+ if (!noAssert) {
5601
+ checkOffset(offset, byteLength, this.length);
5602
+ }
5603
+
5604
+ var val = this[offset + --byteLength];
5605
+ var mul = 1;
5606
+ while (byteLength > 0 && (mul *= 0x100)) {
5607
+ val += this[offset + --byteLength] * mul;
5608
+ }
5609
+
5610
+ return val
5611
+ };
5612
+
5613
+ Buffer.prototype.readUint8 =
5614
+ Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
5615
+ offset = offset >>> 0;
5616
+ if (!noAssert) checkOffset(offset, 1, this.length);
5617
+ return this[offset]
5618
+ };
5619
+
5620
+ Buffer.prototype.readUint16LE =
5621
+ Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
5622
+ offset = offset >>> 0;
5623
+ if (!noAssert) checkOffset(offset, 2, this.length);
5624
+ return this[offset] | (this[offset + 1] << 8)
5625
+ };
5626
+
5627
+ Buffer.prototype.readUint16BE =
5628
+ Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
5629
+ offset = offset >>> 0;
5630
+ if (!noAssert) checkOffset(offset, 2, this.length);
5631
+ return (this[offset] << 8) | this[offset + 1]
5632
+ };
5633
+
5634
+ Buffer.prototype.readUint32LE =
5635
+ Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
5636
+ offset = offset >>> 0;
5637
+ if (!noAssert) checkOffset(offset, 4, this.length);
5638
+
5639
+ return ((this[offset]) |
5640
+ (this[offset + 1] << 8) |
5641
+ (this[offset + 2] << 16)) +
5642
+ (this[offset + 3] * 0x1000000)
5643
+ };
5644
+
5645
+ Buffer.prototype.readUint32BE =
5646
+ Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
5647
+ offset = offset >>> 0;
5648
+ if (!noAssert) checkOffset(offset, 4, this.length);
5649
+
5650
+ return (this[offset] * 0x1000000) +
5651
+ ((this[offset + 1] << 16) |
5652
+ (this[offset + 2] << 8) |
5653
+ this[offset + 3])
5654
+ };
5655
+
5656
+ Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
5657
+ offset = offset >>> 0;
5658
+ byteLength = byteLength >>> 0;
5659
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
5660
+
5661
+ var val = this[offset];
5662
+ var mul = 1;
5663
+ var i = 0;
5664
+ while (++i < byteLength && (mul *= 0x100)) {
5665
+ val += this[offset + i] * mul;
5666
+ }
5667
+ mul *= 0x80;
5668
+
5669
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength);
5670
+
5671
+ return val
5672
+ };
5673
+
5674
+ Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
5675
+ offset = offset >>> 0;
5676
+ byteLength = byteLength >>> 0;
5677
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
5678
+
5679
+ var i = byteLength;
5680
+ var mul = 1;
5681
+ var val = this[offset + --i];
5682
+ while (i > 0 && (mul *= 0x100)) {
5683
+ val += this[offset + --i] * mul;
5684
+ }
5685
+ mul *= 0x80;
5686
+
5687
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength);
5688
+
5689
+ return val
5690
+ };
5691
+
5692
+ Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
5693
+ offset = offset >>> 0;
5694
+ if (!noAssert) checkOffset(offset, 1, this.length);
5695
+ if (!(this[offset] & 0x80)) return (this[offset])
5696
+ return ((0xff - this[offset] + 1) * -1)
5697
+ };
5698
+
5699
+ Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
5700
+ offset = offset >>> 0;
5701
+ if (!noAssert) checkOffset(offset, 2, this.length);
5702
+ var val = this[offset] | (this[offset + 1] << 8);
5703
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
5704
+ };
5705
+
5706
+ Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
5707
+ offset = offset >>> 0;
5708
+ if (!noAssert) checkOffset(offset, 2, this.length);
5709
+ var val = this[offset + 1] | (this[offset] << 8);
5710
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
5711
+ };
5712
+
5713
+ Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
5714
+ offset = offset >>> 0;
5715
+ if (!noAssert) checkOffset(offset, 4, this.length);
5716
+
5717
+ return (this[offset]) |
5718
+ (this[offset + 1] << 8) |
5719
+ (this[offset + 2] << 16) |
5720
+ (this[offset + 3] << 24)
5721
+ };
5722
+
5723
+ Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
5724
+ offset = offset >>> 0;
5725
+ if (!noAssert) checkOffset(offset, 4, this.length);
5726
+
5727
+ return (this[offset] << 24) |
5728
+ (this[offset + 1] << 16) |
5729
+ (this[offset + 2] << 8) |
5730
+ (this[offset + 3])
5731
+ };
5732
+
5733
+ Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
5734
+ offset = offset >>> 0;
5735
+ if (!noAssert) checkOffset(offset, 4, this.length);
5736
+ return ieee754.read(this, offset, true, 23, 4)
5737
+ };
5738
+
5739
+ Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
5740
+ offset = offset >>> 0;
5741
+ if (!noAssert) checkOffset(offset, 4, this.length);
5742
+ return ieee754.read(this, offset, false, 23, 4)
5743
+ };
5744
+
5745
+ Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
5746
+ offset = offset >>> 0;
5747
+ if (!noAssert) checkOffset(offset, 8, this.length);
5748
+ return ieee754.read(this, offset, true, 52, 8)
5749
+ };
5750
+
5751
+ Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
5752
+ offset = offset >>> 0;
5753
+ if (!noAssert) checkOffset(offset, 8, this.length);
5754
+ return ieee754.read(this, offset, false, 52, 8)
5755
+ };
5756
+
5757
+ function checkInt (buf, value, offset, ext, max, min) {
5758
+ if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
5759
+ if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
5760
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
5761
+ }
5762
+
5763
+ Buffer.prototype.writeUintLE =
5764
+ Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
5765
+ value = +value;
5766
+ offset = offset >>> 0;
5767
+ byteLength = byteLength >>> 0;
5768
+ if (!noAssert) {
5769
+ var maxBytes = Math.pow(2, 8 * byteLength) - 1;
5770
+ checkInt(this, value, offset, byteLength, maxBytes, 0);
5771
+ }
5772
+
5773
+ var mul = 1;
5774
+ var i = 0;
5775
+ this[offset] = value & 0xFF;
5776
+ while (++i < byteLength && (mul *= 0x100)) {
5777
+ this[offset + i] = (value / mul) & 0xFF;
5778
+ }
5779
+
5780
+ return offset + byteLength
5781
+ };
5782
+
5783
+ Buffer.prototype.writeUintBE =
5784
+ Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
5785
+ value = +value;
5786
+ offset = offset >>> 0;
5787
+ byteLength = byteLength >>> 0;
5788
+ if (!noAssert) {
5789
+ var maxBytes = Math.pow(2, 8 * byteLength) - 1;
5790
+ checkInt(this, value, offset, byteLength, maxBytes, 0);
5791
+ }
5792
+
5793
+ var i = byteLength - 1;
5794
+ var mul = 1;
5795
+ this[offset + i] = value & 0xFF;
5796
+ while (--i >= 0 && (mul *= 0x100)) {
5797
+ this[offset + i] = (value / mul) & 0xFF;
5798
+ }
5799
+
5800
+ return offset + byteLength
5801
+ };
5802
+
5803
+ Buffer.prototype.writeUint8 =
5804
+ Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
5805
+ value = +value;
5806
+ offset = offset >>> 0;
5807
+ if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
5808
+ this[offset] = (value & 0xff);
5809
+ return offset + 1
5810
+ };
5811
+
5812
+ Buffer.prototype.writeUint16LE =
5813
+ Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
5814
+ value = +value;
5815
+ offset = offset >>> 0;
5816
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
5817
+ this[offset] = (value & 0xff);
5818
+ this[offset + 1] = (value >>> 8);
5819
+ return offset + 2
5820
+ };
5821
+
5822
+ Buffer.prototype.writeUint16BE =
5823
+ Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
5824
+ value = +value;
5825
+ offset = offset >>> 0;
5826
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
5827
+ this[offset] = (value >>> 8);
5828
+ this[offset + 1] = (value & 0xff);
5829
+ return offset + 2
5830
+ };
5831
+
5832
+ Buffer.prototype.writeUint32LE =
5833
+ Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
5834
+ value = +value;
5835
+ offset = offset >>> 0;
5836
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
5837
+ this[offset + 3] = (value >>> 24);
5838
+ this[offset + 2] = (value >>> 16);
5839
+ this[offset + 1] = (value >>> 8);
5840
+ this[offset] = (value & 0xff);
5841
+ return offset + 4
5842
+ };
5843
+
5844
+ Buffer.prototype.writeUint32BE =
5845
+ Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
5846
+ value = +value;
5847
+ offset = offset >>> 0;
5848
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
5849
+ this[offset] = (value >>> 24);
5850
+ this[offset + 1] = (value >>> 16);
5851
+ this[offset + 2] = (value >>> 8);
5852
+ this[offset + 3] = (value & 0xff);
5853
+ return offset + 4
5854
+ };
5855
+
5856
+ Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
5857
+ value = +value;
5858
+ offset = offset >>> 0;
5859
+ if (!noAssert) {
5860
+ var limit = Math.pow(2, (8 * byteLength) - 1);
5861
+
5862
+ checkInt(this, value, offset, byteLength, limit - 1, -limit);
5863
+ }
5864
+
5865
+ var i = 0;
5866
+ var mul = 1;
5867
+ var sub = 0;
5868
+ this[offset] = value & 0xFF;
5869
+ while (++i < byteLength && (mul *= 0x100)) {
5870
+ if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
5871
+ sub = 1;
5872
+ }
5873
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
5874
+ }
5875
+
5876
+ return offset + byteLength
5877
+ };
5878
+
5879
+ Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
5880
+ value = +value;
5881
+ offset = offset >>> 0;
5882
+ if (!noAssert) {
5883
+ var limit = Math.pow(2, (8 * byteLength) - 1);
5884
+
5885
+ checkInt(this, value, offset, byteLength, limit - 1, -limit);
5886
+ }
5887
+
5888
+ var i = byteLength - 1;
5889
+ var mul = 1;
5890
+ var sub = 0;
5891
+ this[offset + i] = value & 0xFF;
5892
+ while (--i >= 0 && (mul *= 0x100)) {
5893
+ if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
5894
+ sub = 1;
5895
+ }
5896
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
5897
+ }
5898
+
5899
+ return offset + byteLength
5900
+ };
5901
+
5902
+ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
5903
+ value = +value;
5904
+ offset = offset >>> 0;
5905
+ if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
5906
+ if (value < 0) value = 0xff + value + 1;
5907
+ this[offset] = (value & 0xff);
5908
+ return offset + 1
5909
+ };
5910
+
5911
+ Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
5912
+ value = +value;
5913
+ offset = offset >>> 0;
5914
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
5915
+ this[offset] = (value & 0xff);
5916
+ this[offset + 1] = (value >>> 8);
5917
+ return offset + 2
5918
+ };
5919
+
5920
+ Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
5921
+ value = +value;
5922
+ offset = offset >>> 0;
5923
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
5924
+ this[offset] = (value >>> 8);
5925
+ this[offset + 1] = (value & 0xff);
5926
+ return offset + 2
5927
+ };
5928
+
5929
+ Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
5930
+ value = +value;
5931
+ offset = offset >>> 0;
5932
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
5933
+ this[offset] = (value & 0xff);
5934
+ this[offset + 1] = (value >>> 8);
5935
+ this[offset + 2] = (value >>> 16);
5936
+ this[offset + 3] = (value >>> 24);
5937
+ return offset + 4
5938
+ };
5939
+
5940
+ Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
5941
+ value = +value;
5942
+ offset = offset >>> 0;
5943
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
5944
+ if (value < 0) value = 0xffffffff + value + 1;
5945
+ this[offset] = (value >>> 24);
5946
+ this[offset + 1] = (value >>> 16);
5947
+ this[offset + 2] = (value >>> 8);
5948
+ this[offset + 3] = (value & 0xff);
5949
+ return offset + 4
5950
+ };
5951
+
5952
+ function checkIEEE754 (buf, value, offset, ext, max, min) {
5953
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
5954
+ if (offset < 0) throw new RangeError('Index out of range')
5955
+ }
5956
+
5957
+ function writeFloat (buf, value, offset, littleEndian, noAssert) {
5958
+ value = +value;
5959
+ offset = offset >>> 0;
5960
+ if (!noAssert) {
5961
+ checkIEEE754(buf, value, offset, 4);
5962
+ }
5963
+ ieee754.write(buf, value, offset, littleEndian, 23, 4);
5964
+ return offset + 4
5965
+ }
5966
+
5967
+ Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
5968
+ return writeFloat(this, value, offset, true, noAssert)
5969
+ };
5970
+
5971
+ Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
5972
+ return writeFloat(this, value, offset, false, noAssert)
5973
+ };
5974
+
5975
+ function writeDouble (buf, value, offset, littleEndian, noAssert) {
5976
+ value = +value;
5977
+ offset = offset >>> 0;
5978
+ if (!noAssert) {
5979
+ checkIEEE754(buf, value, offset, 8);
5980
+ }
5981
+ ieee754.write(buf, value, offset, littleEndian, 52, 8);
5982
+ return offset + 8
5983
+ }
5984
+
5985
+ Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
5986
+ return writeDouble(this, value, offset, true, noAssert)
5987
+ };
5988
+
5989
+ Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
5990
+ return writeDouble(this, value, offset, false, noAssert)
5991
+ };
5992
+
5993
+ // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
5994
+ Buffer.prototype.copy = function copy (target, targetStart, start, end) {
5995
+ if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
5996
+ if (!start) start = 0;
5997
+ if (!end && end !== 0) end = this.length;
5998
+ if (targetStart >= target.length) targetStart = target.length;
5999
+ if (!targetStart) targetStart = 0;
6000
+ if (end > 0 && end < start) end = start;
6001
+
6002
+ // Copy 0 bytes; we're done
6003
+ if (end === start) return 0
6004
+ if (target.length === 0 || this.length === 0) return 0
6005
+
6006
+ // Fatal error conditions
6007
+ if (targetStart < 0) {
6008
+ throw new RangeError('targetStart out of bounds')
6009
+ }
6010
+ if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
6011
+ if (end < 0) throw new RangeError('sourceEnd out of bounds')
6012
+
6013
+ // Are we oob?
6014
+ if (end > this.length) end = this.length;
6015
+ if (target.length - targetStart < end - start) {
6016
+ end = target.length - targetStart + start;
6017
+ }
6018
+
6019
+ var len = end - start;
6020
+
6021
+ if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
6022
+ // Use built-in when available, missing from IE11
6023
+ this.copyWithin(targetStart, start, end);
6024
+ } else {
6025
+ Uint8Array.prototype.set.call(
6026
+ target,
6027
+ this.subarray(start, end),
6028
+ targetStart
6029
+ );
6030
+ }
6031
+
6032
+ return len
6033
+ };
6034
+
6035
+ // Usage:
6036
+ // buffer.fill(number[, offset[, end]])
6037
+ // buffer.fill(buffer[, offset[, end]])
6038
+ // buffer.fill(string[, offset[, end]][, encoding])
6039
+ Buffer.prototype.fill = function fill (val, start, end, encoding) {
6040
+ // Handle string cases:
6041
+ if (typeof val === 'string') {
6042
+ if (typeof start === 'string') {
6043
+ encoding = start;
6044
+ start = 0;
6045
+ end = this.length;
6046
+ } else if (typeof end === 'string') {
6047
+ encoding = end;
6048
+ end = this.length;
6049
+ }
6050
+ if (encoding !== undefined && typeof encoding !== 'string') {
6051
+ throw new TypeError('encoding must be a string')
6052
+ }
6053
+ if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
6054
+ throw new TypeError('Unknown encoding: ' + encoding)
6055
+ }
6056
+ if (val.length === 1) {
6057
+ var code = val.charCodeAt(0);
6058
+ if ((encoding === 'utf8' && code < 128) ||
6059
+ encoding === 'latin1') {
6060
+ // Fast path: If `val` fits into a single byte, use that numeric value.
6061
+ val = code;
6062
+ }
6063
+ }
6064
+ } else if (typeof val === 'number') {
6065
+ val = val & 255;
6066
+ } else if (typeof val === 'boolean') {
6067
+ val = Number(val);
6068
+ }
6069
+
6070
+ // Invalid ranges are not set to a default, so can range check early.
6071
+ if (start < 0 || this.length < start || this.length < end) {
6072
+ throw new RangeError('Out of range index')
6073
+ }
6074
+
6075
+ if (end <= start) {
6076
+ return this
6077
+ }
6078
+
6079
+ start = start >>> 0;
6080
+ end = end === undefined ? this.length : end >>> 0;
6081
+
6082
+ if (!val) val = 0;
6083
+
6084
+ var i;
6085
+ if (typeof val === 'number') {
6086
+ for (i = start; i < end; ++i) {
6087
+ this[i] = val;
6088
+ }
6089
+ } else {
6090
+ var bytes = Buffer.isBuffer(val)
6091
+ ? val
6092
+ : Buffer.from(val, encoding);
6093
+ var len = bytes.length;
6094
+ if (len === 0) {
6095
+ throw new TypeError('The value "' + val +
6096
+ '" is invalid for argument "value"')
6097
+ }
6098
+ for (i = 0; i < end - start; ++i) {
6099
+ this[i + start] = bytes[i % len];
6100
+ }
6101
+ }
6102
+
6103
+ return this
6104
+ };
6105
+
6106
+ // HELPER FUNCTIONS
6107
+ // ================
6108
+
6109
+ var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
6110
+
6111
+ function base64clean (str) {
6112
+ // Node takes equal signs as end of the Base64 encoding
6113
+ str = str.split('=')[0];
6114
+ // Node strips out invalid characters like \n and \t from the string, base64-js does not
6115
+ str = str.trim().replace(INVALID_BASE64_RE, '');
6116
+ // Node converts strings with length < 2 to ''
6117
+ if (str.length < 2) return ''
6118
+ // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
6119
+ while (str.length % 4 !== 0) {
6120
+ str = str + '=';
6121
+ }
6122
+ return str
6123
+ }
6124
+
6125
+ function utf8ToBytes (string, units) {
6126
+ units = units || Infinity;
6127
+ var codePoint;
6128
+ var length = string.length;
6129
+ var leadSurrogate = null;
6130
+ var bytes = [];
6131
+
6132
+ for (var i = 0; i < length; ++i) {
6133
+ codePoint = string.charCodeAt(i);
6134
+
6135
+ // is surrogate component
6136
+ if (codePoint > 0xD7FF && codePoint < 0xE000) {
6137
+ // last char was a lead
6138
+ if (!leadSurrogate) {
6139
+ // no lead yet
6140
+ if (codePoint > 0xDBFF) {
6141
+ // unexpected trail
6142
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
6143
+ continue
6144
+ } else if (i + 1 === length) {
6145
+ // unpaired lead
6146
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
6147
+ continue
6148
+ }
6149
+
6150
+ // valid lead
6151
+ leadSurrogate = codePoint;
6152
+
6153
+ continue
6154
+ }
6155
+
6156
+ // 2 leads in a row
6157
+ if (codePoint < 0xDC00) {
6158
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
6159
+ leadSurrogate = codePoint;
6160
+ continue
6161
+ }
6162
+
6163
+ // valid surrogate pair
6164
+ codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
6165
+ } else if (leadSurrogate) {
6166
+ // valid bmp char, but last char was a lead
6167
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
6168
+ }
6169
+
6170
+ leadSurrogate = null;
6171
+
6172
+ // encode utf8
6173
+ if (codePoint < 0x80) {
6174
+ if ((units -= 1) < 0) break
6175
+ bytes.push(codePoint);
6176
+ } else if (codePoint < 0x800) {
6177
+ if ((units -= 2) < 0) break
6178
+ bytes.push(
6179
+ codePoint >> 0x6 | 0xC0,
6180
+ codePoint & 0x3F | 0x80
6181
+ );
6182
+ } else if (codePoint < 0x10000) {
6183
+ if ((units -= 3) < 0) break
6184
+ bytes.push(
6185
+ codePoint >> 0xC | 0xE0,
6186
+ codePoint >> 0x6 & 0x3F | 0x80,
6187
+ codePoint & 0x3F | 0x80
6188
+ );
6189
+ } else if (codePoint < 0x110000) {
6190
+ if ((units -= 4) < 0) break
6191
+ bytes.push(
6192
+ codePoint >> 0x12 | 0xF0,
6193
+ codePoint >> 0xC & 0x3F | 0x80,
6194
+ codePoint >> 0x6 & 0x3F | 0x80,
6195
+ codePoint & 0x3F | 0x80
6196
+ );
6197
+ } else {
6198
+ throw new Error('Invalid code point')
6199
+ }
6200
+ }
6201
+
6202
+ return bytes
6203
+ }
6204
+
6205
+ function asciiToBytes (str) {
6206
+ var byteArray = [];
6207
+ for (var i = 0; i < str.length; ++i) {
6208
+ // Node's code seems to be doing this and not & 0x7F..
6209
+ byteArray.push(str.charCodeAt(i) & 0xFF);
6210
+ }
6211
+ return byteArray
6212
+ }
6213
+
6214
+ function utf16leToBytes (str, units) {
6215
+ var c, hi, lo;
6216
+ var byteArray = [];
6217
+ for (var i = 0; i < str.length; ++i) {
6218
+ if ((units -= 2) < 0) break
6219
+
6220
+ c = str.charCodeAt(i);
6221
+ hi = c >> 8;
6222
+ lo = c % 256;
6223
+ byteArray.push(lo);
6224
+ byteArray.push(hi);
6225
+ }
6226
+
6227
+ return byteArray
6228
+ }
6229
+
6230
+ function base64ToBytes (str) {
6231
+ return base64.toByteArray(base64clean(str))
6232
+ }
6233
+
6234
+ function blitBuffer (src, dst, offset, length) {
6235
+ for (var i = 0; i < length; ++i) {
6236
+ if ((i + offset >= dst.length) || (i >= src.length)) break
6237
+ dst[i + offset] = src[i];
6238
+ }
6239
+ return i
6240
+ }
6241
+
6242
+ // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
6243
+ // the `instanceof` check but they should be treated as of that type.
6244
+ // See: https://github.com/feross/buffer/issues/166
6245
+ function isInstance (obj, type) {
6246
+ return obj instanceof type ||
6247
+ (obj != null && obj.constructor != null && obj.constructor.name != null &&
6248
+ obj.constructor.name === type.name)
6249
+ }
6250
+ function numberIsNaN (obj) {
6251
+ // For IE11 support
6252
+ return obj !== obj // eslint-disable-line no-self-compare
6253
+ }
6254
+
6255
+ // Create lookup table for `toString('hex')`
6256
+ // See: https://github.com/feross/buffer/issues/219
6257
+ var hexSliceLookupTable = (function () {
6258
+ var alphabet = '0123456789abcdef';
6259
+ var table = new Array(256);
6260
+ for (var i = 0; i < 16; ++i) {
6261
+ var i16 = i * 16;
6262
+ for (var j = 0; j < 16; ++j) {
6263
+ table[i16 + j] = alphabet[i] + alphabet[j];
6264
+ }
6265
+ }
6266
+ return table
6267
+ })();
6268
+ } (buffer));
6269
+ return buffer;
6270
+ }
6271
+
6272
+ var bufferExports = requireBuffer();
1922
6273
 
1923
6274
  var Codecs = {};
1924
6275
 
@@ -2183,7 +6534,7 @@ function requireCodecs () {
2183
6534
  */
2184
6535
  function serializeFrameWithLength(frame) {
2185
6536
  var buffer = serializeFrame(frame);
2186
- var lengthPrefixed = Buffer.allocUnsafe(buffer.length + UINT24_SIZE);
6537
+ var lengthPrefixed = bufferExports.Buffer.allocUnsafe(buffer.length + UINT24_SIZE);
2187
6538
  writeUInt24BE(lengthPrefixed, buffer.length, 0);
2188
6539
  buffer.copy(lengthPrefixed, UINT24_SIZE);
2189
6540
  return lengthPrefixed;
@@ -2334,13 +6685,13 @@ function requireCodecs () {
2334
6685
  function serializeSetupFrame(frame) {
2335
6686
  var resumeTokenLength = frame.resumeToken != null ? frame.resumeToken.byteLength : 0;
2336
6687
  var metadataMimeTypeLength = frame.metadataMimeType != null
2337
- ? Buffer.byteLength(frame.metadataMimeType, "ascii")
6688
+ ? bufferExports.Buffer.byteLength(frame.metadataMimeType, "ascii")
2338
6689
  : 0;
2339
6690
  var dataMimeTypeLength = frame.dataMimeType != null
2340
- ? Buffer.byteLength(frame.dataMimeType, "ascii")
6691
+ ? bufferExports.Buffer.byteLength(frame.dataMimeType, "ascii")
2341
6692
  : 0;
2342
6693
  var payloadLength = getPayloadLength(frame);
2343
- var buffer = Buffer.allocUnsafe(FRAME_HEADER_SIZE +
6694
+ var buffer = bufferExports.Buffer.allocUnsafe(FRAME_HEADER_SIZE +
2344
6695
  SETUP_FIXED_SIZE + //
2345
6696
  (resumeTokenLength ? RESUME_TOKEN_LENGTH_SIZE + resumeTokenLength : 0) +
2346
6697
  metadataMimeTypeLength +
@@ -2371,10 +6722,10 @@ function requireCodecs () {
2371
6722
  function sizeOfSetupFrame(frame) {
2372
6723
  var resumeTokenLength = frame.resumeToken != null ? frame.resumeToken.byteLength : 0;
2373
6724
  var metadataMimeTypeLength = frame.metadataMimeType != null
2374
- ? Buffer.byteLength(frame.metadataMimeType, "ascii")
6725
+ ? bufferExports.Buffer.byteLength(frame.metadataMimeType, "ascii")
2375
6726
  : 0;
2376
6727
  var dataMimeTypeLength = frame.dataMimeType != null
2377
- ? Buffer.byteLength(frame.dataMimeType, "ascii")
6728
+ ? bufferExports.Buffer.byteLength(frame.dataMimeType, "ascii")
2378
6729
  : 0;
2379
6730
  var payloadLength = getPayloadLength(frame);
2380
6731
  return (FRAME_HEADER_SIZE +
@@ -2463,8 +6814,8 @@ function requireCodecs () {
2463
6814
  */
2464
6815
  var ERROR_FIXED_SIZE = 4;
2465
6816
  function serializeErrorFrame(frame) {
2466
- var messageLength = frame.message != null ? Buffer.byteLength(frame.message, "utf8") : 0;
2467
- var buffer = Buffer.allocUnsafe(FRAME_HEADER_SIZE + ERROR_FIXED_SIZE + messageLength);
6817
+ var messageLength = frame.message != null ? bufferExports.Buffer.byteLength(frame.message, "utf8") : 0;
6818
+ var buffer = bufferExports.Buffer.allocUnsafe(FRAME_HEADER_SIZE + ERROR_FIXED_SIZE + messageLength);
2468
6819
  var offset = writeHeader(frame, buffer);
2469
6820
  offset = buffer.writeUInt32BE(frame.code, offset);
2470
6821
  if (frame.message != null) {
@@ -2473,7 +6824,7 @@ function requireCodecs () {
2473
6824
  return buffer;
2474
6825
  }
2475
6826
  function sizeOfErrorFrame(frame) {
2476
- var messageLength = frame.message != null ? Buffer.byteLength(frame.message, "utf8") : 0;
6827
+ var messageLength = frame.message != null ? bufferExports.Buffer.byteLength(frame.message, "utf8") : 0;
2477
6828
  return FRAME_HEADER_SIZE + ERROR_FIXED_SIZE + messageLength;
2478
6829
  }
2479
6830
  /**
@@ -2512,7 +6863,7 @@ function requireCodecs () {
2512
6863
  var KEEPALIVE_FIXED_SIZE = 8;
2513
6864
  function serializeKeepAliveFrame(frame) {
2514
6865
  var dataLength = frame.data != null ? frame.data.byteLength : 0;
2515
- var buffer = Buffer.allocUnsafe(FRAME_HEADER_SIZE + KEEPALIVE_FIXED_SIZE + dataLength);
6866
+ var buffer = bufferExports.Buffer.allocUnsafe(FRAME_HEADER_SIZE + KEEPALIVE_FIXED_SIZE + dataLength);
2516
6867
  var offset = writeHeader(frame, buffer);
2517
6868
  offset = writeUInt64BE(buffer, frame.lastReceivedPosition, offset);
2518
6869
  if (frame.data != null) {
@@ -2557,7 +6908,7 @@ function requireCodecs () {
2557
6908
  var LEASE_FIXED_SIZE = 8;
2558
6909
  function serializeLeaseFrame(frame) {
2559
6910
  var metaLength = frame.metadata != null ? frame.metadata.byteLength : 0;
2560
- var buffer = Buffer.allocUnsafe(FRAME_HEADER_SIZE + LEASE_FIXED_SIZE + metaLength);
6911
+ var buffer = bufferExports.Buffer.allocUnsafe(FRAME_HEADER_SIZE + LEASE_FIXED_SIZE + metaLength);
2561
6912
  var offset = writeHeader(frame, buffer);
2562
6913
  offset = buffer.writeUInt32BE(frame.ttl, offset);
2563
6914
  offset = buffer.writeUInt32BE(frame.requestCount, offset);
@@ -2606,7 +6957,7 @@ function requireCodecs () {
2606
6957
  */
2607
6958
  function serializeRequestFrame(frame) {
2608
6959
  var payloadLength = getPayloadLength(frame);
2609
- var buffer = Buffer.allocUnsafe(FRAME_HEADER_SIZE + payloadLength);
6960
+ var buffer = bufferExports.Buffer.allocUnsafe(FRAME_HEADER_SIZE + payloadLength);
2610
6961
  var offset = writeHeader(frame, buffer);
2611
6962
  writePayload(frame, buffer, offset);
2612
6963
  return buffer;
@@ -2622,13 +6973,13 @@ function requireCodecs () {
2622
6973
  function serializeMetadataPushFrame(frame) {
2623
6974
  var metadata = frame.metadata;
2624
6975
  if (metadata != null) {
2625
- var buffer = Buffer.allocUnsafe(FRAME_HEADER_SIZE + metadata.byteLength);
6976
+ var buffer = bufferExports.Buffer.allocUnsafe(FRAME_HEADER_SIZE + metadata.byteLength);
2626
6977
  var offset = writeHeader(frame, buffer);
2627
6978
  metadata.copy(buffer, offset);
2628
6979
  return buffer;
2629
6980
  }
2630
6981
  else {
2631
- var buffer = Buffer.allocUnsafe(FRAME_HEADER_SIZE);
6982
+ var buffer = bufferExports.Buffer.allocUnsafe(FRAME_HEADER_SIZE);
2632
6983
  writeHeader(frame, buffer);
2633
6984
  return buffer;
2634
6985
  }
@@ -2698,7 +7049,7 @@ function requireCodecs () {
2698
7049
  var REQUEST_MANY_HEADER = 4;
2699
7050
  function serializeRequestManyFrame(frame) {
2700
7051
  var payloadLength = getPayloadLength(frame);
2701
- var buffer = Buffer.allocUnsafe(FRAME_HEADER_SIZE + REQUEST_MANY_HEADER + payloadLength);
7052
+ var buffer = bufferExports.Buffer.allocUnsafe(FRAME_HEADER_SIZE + REQUEST_MANY_HEADER + payloadLength);
2702
7053
  var offset = writeHeader(frame, buffer);
2703
7054
  offset = buffer.writeUInt32BE(frame.requestN, offset);
2704
7055
  writePayload(frame, buffer, offset);
@@ -2767,7 +7118,7 @@ function requireCodecs () {
2767
7118
  */
2768
7119
  var REQUEST_N_HEADER = 4;
2769
7120
  function serializeRequestNFrame(frame) {
2770
- var buffer = Buffer.allocUnsafe(FRAME_HEADER_SIZE + REQUEST_N_HEADER);
7121
+ var buffer = bufferExports.Buffer.allocUnsafe(FRAME_HEADER_SIZE + REQUEST_N_HEADER);
2771
7122
  var offset = writeHeader(frame, buffer);
2772
7123
  buffer.writeUInt32BE(frame.requestN, offset);
2773
7124
  return buffer;
@@ -2799,7 +7150,7 @@ function requireCodecs () {
2799
7150
  * Writes a CANCEL frame to a new buffer and returns it.
2800
7151
  */
2801
7152
  function serializeCancelFrame(frame) {
2802
- var buffer = Buffer.allocUnsafe(FRAME_HEADER_SIZE);
7153
+ var buffer = bufferExports.Buffer.allocUnsafe(FRAME_HEADER_SIZE);
2803
7154
  writeHeader(frame, buffer);
2804
7155
  return buffer;
2805
7156
  }
@@ -2824,7 +7175,7 @@ function requireCodecs () {
2824
7175
  */
2825
7176
  function serializePayloadFrame(frame) {
2826
7177
  var payloadLength = getPayloadLength(frame);
2827
- var buffer = Buffer.allocUnsafe(FRAME_HEADER_SIZE + payloadLength);
7178
+ var buffer = bufferExports.Buffer.allocUnsafe(FRAME_HEADER_SIZE + payloadLength);
2828
7179
  var offset = writeHeader(frame, buffer);
2829
7180
  writePayload(frame, buffer, offset);
2830
7181
  return buffer;
@@ -2863,7 +7214,7 @@ function requireCodecs () {
2863
7214
  var RESUME_FIXED_SIZE = 22;
2864
7215
  function serializeResumeFrame(frame) {
2865
7216
  var resumeTokenLength = frame.resumeToken.byteLength;
2866
- var buffer = Buffer.allocUnsafe(FRAME_HEADER_SIZE + RESUME_FIXED_SIZE + resumeTokenLength);
7217
+ var buffer = bufferExports.Buffer.allocUnsafe(FRAME_HEADER_SIZE + RESUME_FIXED_SIZE + resumeTokenLength);
2867
7218
  var offset = writeHeader(frame, buffer);
2868
7219
  offset = buffer.writeUInt16BE(frame.majorVersion, offset);
2869
7220
  offset = buffer.writeUInt16BE(frame.minorVersion, offset);
@@ -2924,7 +7275,7 @@ function requireCodecs () {
2924
7275
  */
2925
7276
  var RESUME_OK_FIXED_SIZE = 8;
2926
7277
  function serializeResumeOkFrame(frame) {
2927
- var buffer = Buffer.allocUnsafe(FRAME_HEADER_SIZE + RESUME_OK_FIXED_SIZE);
7278
+ var buffer = bufferExports.Buffer.allocUnsafe(FRAME_HEADER_SIZE + RESUME_OK_FIXED_SIZE);
2928
7279
  var offset = writeHeader(frame, buffer);
2929
7280
  writeUInt64BE(buffer, frame.clientPosition, offset);
2930
7281
  return buffer;
@@ -3762,7 +8113,7 @@ function requireFragmenter () {
3762
8113
  metadataLength = payload.metadata.byteLength;
3763
8114
  if (!(metadataLength === 0)) return [3 /*break*/, 1];
3764
8115
  remaining -= Frames_1.Lengths.METADATA;
3765
- metadata = Buffer.allocUnsafe(0);
8116
+ metadata = bufferExports.Buffer.allocUnsafe(0);
3766
8117
  return [3 /*break*/, 6];
3767
8118
  case 1:
3768
8119
  metadataPosition = 0;
@@ -3875,7 +8226,7 @@ function requireFragmenter () {
3875
8226
  metadataLength = payload.metadata.byteLength;
3876
8227
  if (!(metadataLength === 0)) return [3 /*break*/, 1];
3877
8228
  remaining -= Frames_1.Lengths.METADATA;
3878
- metadata = Buffer.allocUnsafe(0);
8229
+ metadata = bufferExports.Buffer.allocUnsafe(0);
3879
8230
  return [3 /*break*/, 6];
3880
8231
  case 1:
3881
8232
  metadataPosition = 0;
@@ -4016,10 +8367,10 @@ function requireReassembler () {
4016
8367
  }
4017
8368
  // TODO: add validation
4018
8369
  holder.data = holder.data
4019
- ? Buffer.concat([holder.data, dataFragment])
8370
+ ? bufferExports.Buffer.concat([holder.data, dataFragment])
4020
8371
  : dataFragment;
4021
8372
  if (holder.metadata && metadataFragment) {
4022
- holder.metadata = Buffer.concat([holder.metadata, metadataFragment]);
8373
+ holder.metadata = bufferExports.Buffer.concat([holder.metadata, metadataFragment]);
4023
8374
  }
4024
8375
  return true;
4025
8376
  }
@@ -4028,12 +8379,12 @@ function requireReassembler () {
4028
8379
  // TODO: add validation
4029
8380
  holder.hasFragments = false;
4030
8381
  var data = holder.data
4031
- ? Buffer.concat([holder.data, dataFragment])
8382
+ ? bufferExports.Buffer.concat([holder.data, dataFragment])
4032
8383
  : dataFragment;
4033
8384
  holder.data = undefined;
4034
8385
  if (holder.metadata) {
4035
8386
  var metadata = metadataFragment
4036
- ? Buffer.concat([holder.metadata, metadataFragment])
8387
+ ? bufferExports.Buffer.concat([holder.metadata, metadataFragment])
4037
8388
  : holder.metadata;
4038
8389
  holder.metadata = undefined;
4039
8390
  return {
@@ -6702,7 +11053,7 @@ function requireDist () {
6702
11053
 
6703
11054
  var distExports = requireDist();
6704
11055
 
6705
- var version = "1.42.0";
11056
+ var version = "1.43.1";
6706
11057
  var PACKAGE = {
6707
11058
  version: version};
6708
11059
 
@@ -6918,7 +11269,7 @@ function requireWebsocketDuplexConnection () {
6918
11269
  };
6919
11270
  _this.handleMessage = function (message) {
6920
11271
  try {
6921
- var buffer = Buffer.from(message.data);
11272
+ var buffer = bufferExports.Buffer.from(message.data);
6922
11273
  var frame = _this.deserializer.deserializeFrame(buffer);
6923
11274
  _this.multiplexerDemultiplexer.handle(frame);
6924
11275
  }
@@ -7224,7 +11575,7 @@ class AbstractRemote {
7224
11575
  else {
7225
11576
  contents = JSON.stringify(js);
7226
11577
  }
7227
- return Buffer.from(contents);
11578
+ return bufferExports$1.Buffer.from(contents);
7228
11579
  }
7229
11580
  const syncQueueRequestSize = fetchStrategy == FetchStrategy.Buffered ? 10 : 1;
7230
11581
  const request = await this.buildRequest(path);
@@ -9615,7 +13966,7 @@ SELECT * FROM crud_entries;
9615
13966
  * @returns An AsyncIterable that yields QueryResults whenever the data changes
9616
13967
  */
9617
13968
  watchWithAsyncGenerator(sql, parameters, options) {
9618
- return new EventIterator((eventOptions) => {
13969
+ return new domExports.EventIterator((eventOptions) => {
9619
13970
  const handler = {
9620
13971
  onResult: (result) => {
9621
13972
  eventOptions.push(result);
@@ -9725,7 +14076,7 @@ SELECT * FROM crud_entries;
9725
14076
  */
9726
14077
  onChangeWithAsyncGenerator(options) {
9727
14078
  const resolvedOptions = options ?? {};
9728
- return new EventIterator((eventOptions) => {
14079
+ return new domExports.EventIterator((eventOptions) => {
9729
14080
  const dispose = this.onChangeWithCallback({
9730
14081
  onChange: (event) => {
9731
14082
  eventOptions.push(event);
@@ -10055,7 +14406,7 @@ class SqliteBucketStorage extends BaseObserver {
10055
14406
  // Nothing to update
10056
14407
  return false;
10057
14408
  }
10058
- const rs = await this.db.getAll("SELECT seq FROM sqlite_sequence WHERE name = 'ps_crud'");
14409
+ const rs = await this.db.getAll("SELECT seq FROM main.sqlite_sequence WHERE name = 'ps_crud'");
10059
14410
  if (!rs.length) {
10060
14411
  // Nothing to update
10061
14412
  return false;
@@ -10069,7 +14420,7 @@ class SqliteBucketStorage extends BaseObserver {
10069
14420
  this.logger.debug(`New data uploaded since write checkpoint ${opId} - need new write checkpoint`);
10070
14421
  return false;
10071
14422
  }
10072
- const rs = await tx.execute("SELECT seq FROM sqlite_sequence WHERE name = 'ps_crud'");
14423
+ const rs = await tx.execute("SELECT seq FROM main.sqlite_sequence WHERE name = 'ps_crud'");
10073
14424
  if (!rs.rows?.length) {
10074
14425
  // assert isNotEmpty
10075
14426
  throw new Error('SQLite Sequence should not be empty');