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