@xata.io/client 0.29.3 → 0.29.4
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/.turbo/turbo-add-version.log +1 -1
- package/.turbo/turbo-build.log +3 -3
- package/CHANGELOG.md +8 -0
- package/dist/index.cjs +1819 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +620 -9
- package/dist/index.mjs +1818 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -24,6 +24,1814 @@ const TraceAttributes = {
|
|
24
24
|
CLOUDFLARE_RAY_ID: "cf.ray"
|
25
25
|
};
|
26
26
|
|
27
|
+
const lookup = [];
|
28
|
+
const revLookup = [];
|
29
|
+
const code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
30
|
+
for (let i = 0, len = code.length; i < len; ++i) {
|
31
|
+
lookup[i] = code[i];
|
32
|
+
revLookup[code.charCodeAt(i)] = i;
|
33
|
+
}
|
34
|
+
revLookup["-".charCodeAt(0)] = 62;
|
35
|
+
revLookup["_".charCodeAt(0)] = 63;
|
36
|
+
function getLens(b64) {
|
37
|
+
const len = b64.length;
|
38
|
+
if (len % 4 > 0) {
|
39
|
+
throw new Error("Invalid string. Length must be a multiple of 4");
|
40
|
+
}
|
41
|
+
let validLen = b64.indexOf("=");
|
42
|
+
if (validLen === -1)
|
43
|
+
validLen = len;
|
44
|
+
const placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4;
|
45
|
+
return [validLen, placeHoldersLen];
|
46
|
+
}
|
47
|
+
function _byteLength(_b64, validLen, placeHoldersLen) {
|
48
|
+
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
49
|
+
}
|
50
|
+
function toByteArray(b64) {
|
51
|
+
let tmp;
|
52
|
+
const lens = getLens(b64);
|
53
|
+
const validLen = lens[0];
|
54
|
+
const placeHoldersLen = lens[1];
|
55
|
+
const arr = new Uint8Array(_byteLength(b64, validLen, placeHoldersLen));
|
56
|
+
let curByte = 0;
|
57
|
+
const len = placeHoldersLen > 0 ? validLen - 4 : validLen;
|
58
|
+
let i;
|
59
|
+
for (i = 0; i < len; i += 4) {
|
60
|
+
tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)];
|
61
|
+
arr[curByte++] = tmp >> 16 & 255;
|
62
|
+
arr[curByte++] = tmp >> 8 & 255;
|
63
|
+
arr[curByte++] = tmp & 255;
|
64
|
+
}
|
65
|
+
if (placeHoldersLen === 2) {
|
66
|
+
tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4;
|
67
|
+
arr[curByte++] = tmp & 255;
|
68
|
+
}
|
69
|
+
if (placeHoldersLen === 1) {
|
70
|
+
tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2;
|
71
|
+
arr[curByte++] = tmp >> 8 & 255;
|
72
|
+
arr[curByte++] = tmp & 255;
|
73
|
+
}
|
74
|
+
return arr;
|
75
|
+
}
|
76
|
+
function tripletToBase64(num) {
|
77
|
+
return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
|
78
|
+
}
|
79
|
+
function encodeChunk(uint8, start, end) {
|
80
|
+
let tmp;
|
81
|
+
const output = [];
|
82
|
+
for (let i = start; i < end; i += 3) {
|
83
|
+
tmp = (uint8[i] << 16 & 16711680) + (uint8[i + 1] << 8 & 65280) + (uint8[i + 2] & 255);
|
84
|
+
output.push(tripletToBase64(tmp));
|
85
|
+
}
|
86
|
+
return output.join("");
|
87
|
+
}
|
88
|
+
function fromByteArray(uint8) {
|
89
|
+
let tmp;
|
90
|
+
const len = uint8.length;
|
91
|
+
const extraBytes = len % 3;
|
92
|
+
const parts = [];
|
93
|
+
const maxChunkLength = 16383;
|
94
|
+
for (let i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
|
95
|
+
parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength));
|
96
|
+
}
|
97
|
+
if (extraBytes === 1) {
|
98
|
+
tmp = uint8[len - 1];
|
99
|
+
parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "==");
|
100
|
+
} else if (extraBytes === 2) {
|
101
|
+
tmp = (uint8[len - 2] << 8) + uint8[len - 1];
|
102
|
+
parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "=");
|
103
|
+
}
|
104
|
+
return parts.join("");
|
105
|
+
}
|
106
|
+
|
107
|
+
const K_MAX_LENGTH = 2147483647;
|
108
|
+
const MAX_ARGUMENTS_LENGTH = 4096;
|
109
|
+
class Buffer extends Uint8Array {
|
110
|
+
/**
|
111
|
+
* Constructs a new `Buffer` instance.
|
112
|
+
*
|
113
|
+
* @param value
|
114
|
+
* @param encodingOrOffset
|
115
|
+
* @param length
|
116
|
+
*/
|
117
|
+
constructor(value, encodingOrOffset, length) {
|
118
|
+
if (typeof value === "number") {
|
119
|
+
if (typeof encodingOrOffset === "string") {
|
120
|
+
throw new TypeError("The first argument must be of type string, received type number");
|
121
|
+
}
|
122
|
+
if (value < 0) {
|
123
|
+
throw new RangeError("The buffer size cannot be negative");
|
124
|
+
}
|
125
|
+
super(value < 0 ? 0 : Buffer._checked(value) | 0);
|
126
|
+
} else if (typeof value === "string") {
|
127
|
+
if (typeof encodingOrOffset !== "string") {
|
128
|
+
encodingOrOffset = "utf8";
|
129
|
+
}
|
130
|
+
if (!Buffer.isEncoding(encodingOrOffset)) {
|
131
|
+
throw new TypeError("Unknown encoding: " + encodingOrOffset);
|
132
|
+
}
|
133
|
+
const length2 = Buffer.byteLength(value, encodingOrOffset) | 0;
|
134
|
+
super(length2);
|
135
|
+
const written = this.write(value, 0, this.length, encodingOrOffset);
|
136
|
+
if (written !== length2) {
|
137
|
+
throw new TypeError(
|
138
|
+
"Number of bytes written did not match expected length (wrote " + written + ", expected " + length2 + ")"
|
139
|
+
);
|
140
|
+
}
|
141
|
+
} else if (ArrayBuffer.isView(value)) {
|
142
|
+
if (Buffer._isInstance(value, Uint8Array)) {
|
143
|
+
const copy = new Uint8Array(value);
|
144
|
+
const array = copy.buffer;
|
145
|
+
const byteOffset = copy.byteOffset;
|
146
|
+
const length2 = copy.byteLength;
|
147
|
+
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
148
|
+
throw new RangeError("offset is outside of buffer bounds");
|
149
|
+
}
|
150
|
+
if (array.byteLength < byteOffset + (length2 || 0)) {
|
151
|
+
throw new RangeError("length is outside of buffer bounds");
|
152
|
+
}
|
153
|
+
super(new Uint8Array(array, byteOffset, length2));
|
154
|
+
} else {
|
155
|
+
const array = value;
|
156
|
+
const length2 = array.length < 0 ? 0 : Buffer._checked(array.length) | 0;
|
157
|
+
super(new Uint8Array(length2));
|
158
|
+
for (let i = 0; i < length2; i++) {
|
159
|
+
this[i] = array[i] & 255;
|
160
|
+
}
|
161
|
+
}
|
162
|
+
} else if (value == null) {
|
163
|
+
throw new TypeError(
|
164
|
+
"The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value
|
165
|
+
);
|
166
|
+
} else if (Buffer._isInstance(value, ArrayBuffer) || value && Buffer._isInstance(value.buffer, ArrayBuffer)) {
|
167
|
+
const array = value;
|
168
|
+
const byteOffset = encodingOrOffset;
|
169
|
+
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
170
|
+
throw new RangeError("offset is outside of buffer bounds");
|
171
|
+
}
|
172
|
+
if (array.byteLength < byteOffset + (length || 0)) {
|
173
|
+
throw new RangeError("length is outside of buffer bounds");
|
174
|
+
}
|
175
|
+
super(new Uint8Array(array, byteOffset, length));
|
176
|
+
} else if (Array.isArray(value)) {
|
177
|
+
const array = value;
|
178
|
+
const length2 = array.length < 0 ? 0 : Buffer._checked(array.length) | 0;
|
179
|
+
super(new Uint8Array(length2));
|
180
|
+
for (let i = 0; i < length2; i++) {
|
181
|
+
this[i] = array[i] & 255;
|
182
|
+
}
|
183
|
+
} else {
|
184
|
+
throw new TypeError("Unable to determine the correct way to allocate buffer for type " + typeof value);
|
185
|
+
}
|
186
|
+
}
|
187
|
+
/**
|
188
|
+
* Return JSON representation of the buffer.
|
189
|
+
*/
|
190
|
+
toJSON() {
|
191
|
+
return {
|
192
|
+
type: "Buffer",
|
193
|
+
data: Array.prototype.slice.call(this)
|
194
|
+
};
|
195
|
+
}
|
196
|
+
/**
|
197
|
+
* Writes `string` to the buffer at `offset` according to the character encoding in `encoding`. The `length`
|
198
|
+
* parameter is the number of bytes to write. If the buffer does not contain enough space to fit the entire string,
|
199
|
+
* only part of `string` will be written. However, partially encoded characters will not be written.
|
200
|
+
*
|
201
|
+
* @param string String to write to `buf`.
|
202
|
+
* @param offset Number of bytes to skip before starting to write `string`. Default: `0`.
|
203
|
+
* @param length Maximum number of bytes to write: Default: `buf.length - offset`.
|
204
|
+
* @param encoding The character encoding of `string`. Default: `utf8`.
|
205
|
+
*/
|
206
|
+
write(string, offset, length, encoding) {
|
207
|
+
if (typeof offset === "undefined") {
|
208
|
+
encoding = "utf8";
|
209
|
+
length = this.length;
|
210
|
+
offset = 0;
|
211
|
+
} else if (typeof length === "undefined" && typeof offset === "string") {
|
212
|
+
encoding = offset;
|
213
|
+
length = this.length;
|
214
|
+
offset = 0;
|
215
|
+
} else if (typeof offset === "number" && isFinite(offset)) {
|
216
|
+
offset = offset >>> 0;
|
217
|
+
if (typeof length === "number" && isFinite(length)) {
|
218
|
+
length = length >>> 0;
|
219
|
+
encoding ?? (encoding = "utf8");
|
220
|
+
} else if (typeof length === "string") {
|
221
|
+
encoding = length;
|
222
|
+
length = void 0;
|
223
|
+
}
|
224
|
+
} else {
|
225
|
+
throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");
|
226
|
+
}
|
227
|
+
const remaining = this.length - offset;
|
228
|
+
if (typeof length === "undefined" || length > remaining) {
|
229
|
+
length = remaining;
|
230
|
+
}
|
231
|
+
if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
|
232
|
+
throw new RangeError("Attempt to write outside buffer bounds");
|
233
|
+
}
|
234
|
+
encoding || (encoding = "utf8");
|
235
|
+
switch (Buffer._getEncoding(encoding)) {
|
236
|
+
case "hex":
|
237
|
+
return Buffer._hexWrite(this, string, offset, length);
|
238
|
+
case "utf8":
|
239
|
+
return Buffer._utf8Write(this, string, offset, length);
|
240
|
+
case "ascii":
|
241
|
+
case "latin1":
|
242
|
+
case "binary":
|
243
|
+
return Buffer._asciiWrite(this, string, offset, length);
|
244
|
+
case "ucs2":
|
245
|
+
case "utf16le":
|
246
|
+
return Buffer._ucs2Write(this, string, offset, length);
|
247
|
+
case "base64":
|
248
|
+
return Buffer._base64Write(this, string, offset, length);
|
249
|
+
}
|
250
|
+
}
|
251
|
+
/**
|
252
|
+
* Decodes the buffer to a string according to the specified character encoding.
|
253
|
+
* Passing `start` and `end` will decode only a subset of the buffer.
|
254
|
+
*
|
255
|
+
* Note that if the encoding is `utf8` and a byte sequence in the input is not valid UTF-8, then each invalid byte
|
256
|
+
* will be replaced with `U+FFFD`.
|
257
|
+
*
|
258
|
+
* @param encoding
|
259
|
+
* @param start
|
260
|
+
* @param end
|
261
|
+
*/
|
262
|
+
toString(encoding, start, end) {
|
263
|
+
const length = this.length;
|
264
|
+
if (length === 0) {
|
265
|
+
return "";
|
266
|
+
}
|
267
|
+
if (arguments.length === 0) {
|
268
|
+
return Buffer._utf8Slice(this, 0, length);
|
269
|
+
}
|
270
|
+
if (typeof start === "undefined" || start < 0) {
|
271
|
+
start = 0;
|
272
|
+
}
|
273
|
+
if (start > this.length) {
|
274
|
+
return "";
|
275
|
+
}
|
276
|
+
if (typeof end === "undefined" || end > this.length) {
|
277
|
+
end = this.length;
|
278
|
+
}
|
279
|
+
if (end <= 0) {
|
280
|
+
return "";
|
281
|
+
}
|
282
|
+
end >>>= 0;
|
283
|
+
start >>>= 0;
|
284
|
+
if (end <= start) {
|
285
|
+
return "";
|
286
|
+
}
|
287
|
+
if (!encoding) {
|
288
|
+
encoding = "utf8";
|
289
|
+
}
|
290
|
+
switch (Buffer._getEncoding(encoding)) {
|
291
|
+
case "hex":
|
292
|
+
return Buffer._hexSlice(this, start, end);
|
293
|
+
case "utf8":
|
294
|
+
return Buffer._utf8Slice(this, start, end);
|
295
|
+
case "ascii":
|
296
|
+
return Buffer._asciiSlice(this, start, end);
|
297
|
+
case "latin1":
|
298
|
+
case "binary":
|
299
|
+
return Buffer._latin1Slice(this, start, end);
|
300
|
+
case "ucs2":
|
301
|
+
case "utf16le":
|
302
|
+
return Buffer._utf16leSlice(this, start, end);
|
303
|
+
case "base64":
|
304
|
+
return Buffer._base64Slice(this, start, end);
|
305
|
+
}
|
306
|
+
}
|
307
|
+
/**
|
308
|
+
* Returns true if this buffer's is equal to the provided buffer, meaning they share the same exact data.
|
309
|
+
*
|
310
|
+
* @param otherBuffer
|
311
|
+
*/
|
312
|
+
equals(otherBuffer) {
|
313
|
+
if (!Buffer.isBuffer(otherBuffer)) {
|
314
|
+
throw new TypeError("Argument must be a Buffer");
|
315
|
+
}
|
316
|
+
if (this === otherBuffer) {
|
317
|
+
return true;
|
318
|
+
}
|
319
|
+
return Buffer.compare(this, otherBuffer) === 0;
|
320
|
+
}
|
321
|
+
/**
|
322
|
+
* Compares the buffer with `otherBuffer` and returns a number indicating whether the buffer comes before, after,
|
323
|
+
* or is the same as `otherBuffer` in sort order. Comparison is based on the actual sequence of bytes in each
|
324
|
+
* buffer.
|
325
|
+
*
|
326
|
+
* - `0` is returned if `otherBuffer` is the same as this buffer.
|
327
|
+
* - `1` is returned if `otherBuffer` should come before this buffer when sorted.
|
328
|
+
* - `-1` is returned if `otherBuffer` should come after this buffer when sorted.
|
329
|
+
*
|
330
|
+
* @param otherBuffer The buffer to compare to.
|
331
|
+
* @param targetStart The offset within `otherBuffer` at which to begin comparison.
|
332
|
+
* @param targetEnd The offset within `otherBuffer` at which to end comparison (exclusive).
|
333
|
+
* @param sourceStart The offset within this buffer at which to begin comparison.
|
334
|
+
* @param sourceEnd The offset within this buffer at which to end the comparison (exclusive).
|
335
|
+
*/
|
336
|
+
compare(otherBuffer, targetStart, targetEnd, sourceStart, sourceEnd) {
|
337
|
+
if (Buffer._isInstance(otherBuffer, Uint8Array)) {
|
338
|
+
otherBuffer = Buffer.from(otherBuffer, otherBuffer.byteOffset, otherBuffer.byteLength);
|
339
|
+
}
|
340
|
+
if (!Buffer.isBuffer(otherBuffer)) {
|
341
|
+
throw new TypeError("Argument must be a Buffer or Uint8Array");
|
342
|
+
}
|
343
|
+
targetStart ?? (targetStart = 0);
|
344
|
+
targetEnd ?? (targetEnd = otherBuffer ? otherBuffer.length : 0);
|
345
|
+
sourceStart ?? (sourceStart = 0);
|
346
|
+
sourceEnd ?? (sourceEnd = this.length);
|
347
|
+
if (targetStart < 0 || targetEnd > otherBuffer.length || sourceStart < 0 || sourceEnd > this.length) {
|
348
|
+
throw new RangeError("Out of range index");
|
349
|
+
}
|
350
|
+
if (sourceStart >= sourceEnd && targetStart >= targetEnd) {
|
351
|
+
return 0;
|
352
|
+
}
|
353
|
+
if (sourceStart >= sourceEnd) {
|
354
|
+
return -1;
|
355
|
+
}
|
356
|
+
if (targetStart >= targetEnd) {
|
357
|
+
return 1;
|
358
|
+
}
|
359
|
+
targetStart >>>= 0;
|
360
|
+
targetEnd >>>= 0;
|
361
|
+
sourceStart >>>= 0;
|
362
|
+
sourceEnd >>>= 0;
|
363
|
+
if (this === otherBuffer) {
|
364
|
+
return 0;
|
365
|
+
}
|
366
|
+
let x = sourceEnd - sourceStart;
|
367
|
+
let y = targetEnd - targetStart;
|
368
|
+
const len = Math.min(x, y);
|
369
|
+
const thisCopy = this.slice(sourceStart, sourceEnd);
|
370
|
+
const targetCopy = otherBuffer.slice(targetStart, targetEnd);
|
371
|
+
for (let i = 0; i < len; ++i) {
|
372
|
+
if (thisCopy[i] !== targetCopy[i]) {
|
373
|
+
x = thisCopy[i];
|
374
|
+
y = targetCopy[i];
|
375
|
+
break;
|
376
|
+
}
|
377
|
+
}
|
378
|
+
if (x < y)
|
379
|
+
return -1;
|
380
|
+
if (y < x)
|
381
|
+
return 1;
|
382
|
+
return 0;
|
383
|
+
}
|
384
|
+
/**
|
385
|
+
* Copies data from a region of this buffer to a region in `targetBuffer`, even if the `targetBuffer` memory
|
386
|
+
* region overlaps with this buffer.
|
387
|
+
*
|
388
|
+
* @param targetBuffer The target buffer to copy into.
|
389
|
+
* @param targetStart The offset within `targetBuffer` at which to begin writing.
|
390
|
+
* @param sourceStart The offset within this buffer at which to begin copying.
|
391
|
+
* @param sourceEnd The offset within this buffer at which to end copying (exclusive).
|
392
|
+
*/
|
393
|
+
copy(targetBuffer, targetStart, sourceStart, sourceEnd) {
|
394
|
+
if (!Buffer.isBuffer(targetBuffer))
|
395
|
+
throw new TypeError("argument should be a Buffer");
|
396
|
+
if (!sourceStart)
|
397
|
+
sourceStart = 0;
|
398
|
+
if (!targetStart)
|
399
|
+
targetStart = 0;
|
400
|
+
if (!sourceEnd && sourceEnd !== 0)
|
401
|
+
sourceEnd = this.length;
|
402
|
+
if (targetStart >= targetBuffer.length)
|
403
|
+
targetStart = targetBuffer.length;
|
404
|
+
if (!targetStart)
|
405
|
+
targetStart = 0;
|
406
|
+
if (sourceEnd > 0 && sourceEnd < sourceStart)
|
407
|
+
sourceEnd = sourceStart;
|
408
|
+
if (sourceEnd === sourceStart)
|
409
|
+
return 0;
|
410
|
+
if (targetBuffer.length === 0 || this.length === 0)
|
411
|
+
return 0;
|
412
|
+
if (targetStart < 0) {
|
413
|
+
throw new RangeError("targetStart out of bounds");
|
414
|
+
}
|
415
|
+
if (sourceStart < 0 || sourceStart >= this.length)
|
416
|
+
throw new RangeError("Index out of range");
|
417
|
+
if (sourceEnd < 0)
|
418
|
+
throw new RangeError("sourceEnd out of bounds");
|
419
|
+
if (sourceEnd > this.length)
|
420
|
+
sourceEnd = this.length;
|
421
|
+
if (targetBuffer.length - targetStart < sourceEnd - sourceStart) {
|
422
|
+
sourceEnd = targetBuffer.length - targetStart + sourceStart;
|
423
|
+
}
|
424
|
+
const len = sourceEnd - sourceStart;
|
425
|
+
if (this === targetBuffer && typeof Uint8Array.prototype.copyWithin === "function") {
|
426
|
+
this.copyWithin(targetStart, sourceStart, sourceEnd);
|
427
|
+
} else {
|
428
|
+
Uint8Array.prototype.set.call(targetBuffer, this.subarray(sourceStart, sourceEnd), targetStart);
|
429
|
+
}
|
430
|
+
return len;
|
431
|
+
}
|
432
|
+
/**
|
433
|
+
* Returns a new `Buffer` that references the same memory as the original, but offset and cropped by the `start`
|
434
|
+
* and `end` indices. This is the same behavior as `buf.subarray()`.
|
435
|
+
*
|
436
|
+
* This method is not compatible with the `Uint8Array.prototype.slice()`, which is a superclass of Buffer. To copy
|
437
|
+
* the slice, use `Uint8Array.prototype.slice()`.
|
438
|
+
*
|
439
|
+
* @param start
|
440
|
+
* @param end
|
441
|
+
*/
|
442
|
+
slice(start, end) {
|
443
|
+
if (!start) {
|
444
|
+
start = 0;
|
445
|
+
}
|
446
|
+
const len = this.length;
|
447
|
+
start = ~~start;
|
448
|
+
end = end === void 0 ? len : ~~end;
|
449
|
+
if (start < 0) {
|
450
|
+
start += len;
|
451
|
+
if (start < 0) {
|
452
|
+
start = 0;
|
453
|
+
}
|
454
|
+
} else if (start > len) {
|
455
|
+
start = len;
|
456
|
+
}
|
457
|
+
if (end < 0) {
|
458
|
+
end += len;
|
459
|
+
if (end < 0) {
|
460
|
+
end = 0;
|
461
|
+
}
|
462
|
+
} else if (end > len) {
|
463
|
+
end = len;
|
464
|
+
}
|
465
|
+
if (end < start) {
|
466
|
+
end = start;
|
467
|
+
}
|
468
|
+
const newBuf = this.subarray(start, end);
|
469
|
+
Object.setPrototypeOf(newBuf, Buffer.prototype);
|
470
|
+
return newBuf;
|
471
|
+
}
|
472
|
+
/**
|
473
|
+
* Writes `byteLength` bytes of `value` to `buf` at the specified `offset` as little-endian. Supports up to 48 bits
|
474
|
+
* of accuracy. Behavior is undefined when value is anything other than an unsigned integer.
|
475
|
+
*
|
476
|
+
* @param value Number to write.
|
477
|
+
* @param offset Number of bytes to skip before starting to write.
|
478
|
+
* @param byteLength Number of bytes to write, between 0 and 6.
|
479
|
+
* @param noAssert
|
480
|
+
* @returns `offset` plus the number of bytes written.
|
481
|
+
*/
|
482
|
+
writeUIntLE(value, offset, byteLength, noAssert) {
|
483
|
+
value = +value;
|
484
|
+
offset = offset >>> 0;
|
485
|
+
byteLength = byteLength >>> 0;
|
486
|
+
if (!noAssert) {
|
487
|
+
const maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
488
|
+
Buffer._checkInt(this, value, offset, byteLength, maxBytes, 0);
|
489
|
+
}
|
490
|
+
let mul = 1;
|
491
|
+
let i = 0;
|
492
|
+
this[offset] = value & 255;
|
493
|
+
while (++i < byteLength && (mul *= 256)) {
|
494
|
+
this[offset + i] = value / mul & 255;
|
495
|
+
}
|
496
|
+
return offset + byteLength;
|
497
|
+
}
|
498
|
+
/**
|
499
|
+
* Writes `byteLength` bytes of `value` to `buf` at the specified `offset` as big-endian. Supports up to 48 bits of
|
500
|
+
* accuracy. Behavior is undefined when `value` is anything other than an unsigned integer.
|
501
|
+
*
|
502
|
+
* @param value Number to write.
|
503
|
+
* @param offset Number of bytes to skip before starting to write.
|
504
|
+
* @param byteLength Number of bytes to write, between 0 and 6.
|
505
|
+
* @param noAssert
|
506
|
+
* @returns `offset` plus the number of bytes written.
|
507
|
+
*/
|
508
|
+
writeUIntBE(value, offset, byteLength, noAssert) {
|
509
|
+
value = +value;
|
510
|
+
offset = offset >>> 0;
|
511
|
+
byteLength = byteLength >>> 0;
|
512
|
+
if (!noAssert) {
|
513
|
+
const maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
514
|
+
Buffer._checkInt(this, value, offset, byteLength, maxBytes, 0);
|
515
|
+
}
|
516
|
+
let i = byteLength - 1;
|
517
|
+
let mul = 1;
|
518
|
+
this[offset + i] = value & 255;
|
519
|
+
while (--i >= 0 && (mul *= 256)) {
|
520
|
+
this[offset + i] = value / mul & 255;
|
521
|
+
}
|
522
|
+
return offset + byteLength;
|
523
|
+
}
|
524
|
+
/**
|
525
|
+
* Writes `byteLength` bytes of `value` to `buf` at the specified `offset` as little-endian. Supports up to 48 bits
|
526
|
+
* of accuracy. Behavior is undefined when `value` is anything other than a signed integer.
|
527
|
+
*
|
528
|
+
* @param value Number to write.
|
529
|
+
* @param offset Number of bytes to skip before starting to write.
|
530
|
+
* @param byteLength Number of bytes to write, between 0 and 6.
|
531
|
+
* @param noAssert
|
532
|
+
* @returns `offset` plus the number of bytes written.
|
533
|
+
*/
|
534
|
+
writeIntLE(value, offset, byteLength, noAssert) {
|
535
|
+
value = +value;
|
536
|
+
offset = offset >>> 0;
|
537
|
+
if (!noAssert) {
|
538
|
+
const limit = Math.pow(2, 8 * byteLength - 1);
|
539
|
+
Buffer._checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
540
|
+
}
|
541
|
+
let i = 0;
|
542
|
+
let mul = 1;
|
543
|
+
let sub = 0;
|
544
|
+
this[offset] = value & 255;
|
545
|
+
while (++i < byteLength && (mul *= 256)) {
|
546
|
+
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
547
|
+
sub = 1;
|
548
|
+
}
|
549
|
+
this[offset + i] = (value / mul >> 0) - sub & 255;
|
550
|
+
}
|
551
|
+
return offset + byteLength;
|
552
|
+
}
|
553
|
+
/**
|
554
|
+
* Writes `byteLength` bytes of `value` to `buf` at the specified `offset` as big-endian. Supports up to 48 bits
|
555
|
+
* of accuracy. Behavior is undefined when `value` is anything other than a signed integer.
|
556
|
+
*
|
557
|
+
* @param value Number to write.
|
558
|
+
* @param offset Number of bytes to skip before starting to write.
|
559
|
+
* @param byteLength Number of bytes to write, between 0 and 6.
|
560
|
+
* @param noAssert
|
561
|
+
* @returns `offset` plus the number of bytes written.
|
562
|
+
*/
|
563
|
+
writeIntBE(value, offset, byteLength, noAssert) {
|
564
|
+
value = +value;
|
565
|
+
offset = offset >>> 0;
|
566
|
+
if (!noAssert) {
|
567
|
+
const limit = Math.pow(2, 8 * byteLength - 1);
|
568
|
+
Buffer._checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
569
|
+
}
|
570
|
+
let i = byteLength - 1;
|
571
|
+
let mul = 1;
|
572
|
+
let sub = 0;
|
573
|
+
this[offset + i] = value & 255;
|
574
|
+
while (--i >= 0 && (mul *= 256)) {
|
575
|
+
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
576
|
+
sub = 1;
|
577
|
+
}
|
578
|
+
this[offset + i] = (value / mul >> 0) - sub & 255;
|
579
|
+
}
|
580
|
+
return offset + byteLength;
|
581
|
+
}
|
582
|
+
/**
|
583
|
+
* Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as an
|
584
|
+
* unsigned, little-endian integer supporting up to 48 bits of accuracy.
|
585
|
+
*
|
586
|
+
* @param offset Number of bytes to skip before starting to read.
|
587
|
+
* @param byteLength Number of bytes to read, between 0 and 6.
|
588
|
+
* @param noAssert
|
589
|
+
*/
|
590
|
+
readUIntLE(offset, byteLength, noAssert) {
|
591
|
+
offset = offset >>> 0;
|
592
|
+
byteLength = byteLength >>> 0;
|
593
|
+
if (!noAssert) {
|
594
|
+
Buffer._checkOffset(offset, byteLength, this.length);
|
595
|
+
}
|
596
|
+
let val = this[offset];
|
597
|
+
let mul = 1;
|
598
|
+
let i = 0;
|
599
|
+
while (++i < byteLength && (mul *= 256)) {
|
600
|
+
val += this[offset + i] * mul;
|
601
|
+
}
|
602
|
+
return val;
|
603
|
+
}
|
604
|
+
/**
|
605
|
+
* Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as an
|
606
|
+
* unsigned, big-endian integer supporting up to 48 bits of accuracy.
|
607
|
+
*
|
608
|
+
* @param offset Number of bytes to skip before starting to read.
|
609
|
+
* @param byteLength Number of bytes to read, between 0 and 6.
|
610
|
+
* @param noAssert
|
611
|
+
*/
|
612
|
+
readUIntBE(offset, byteLength, noAssert) {
|
613
|
+
offset = offset >>> 0;
|
614
|
+
byteLength = byteLength >>> 0;
|
615
|
+
if (!noAssert) {
|
616
|
+
Buffer._checkOffset(offset, byteLength, this.length);
|
617
|
+
}
|
618
|
+
let val = this[offset + --byteLength];
|
619
|
+
let mul = 1;
|
620
|
+
while (byteLength > 0 && (mul *= 256)) {
|
621
|
+
val += this[offset + --byteLength] * mul;
|
622
|
+
}
|
623
|
+
return val;
|
624
|
+
}
|
625
|
+
/**
|
626
|
+
* Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as a
|
627
|
+
* little-endian, two's complement signed value supporting up to 48 bits of accuracy.
|
628
|
+
*
|
629
|
+
* @param offset Number of bytes to skip before starting to read.
|
630
|
+
* @param byteLength Number of bytes to read, between 0 and 6.
|
631
|
+
* @param noAssert
|
632
|
+
*/
|
633
|
+
readIntLE(offset, byteLength, noAssert) {
|
634
|
+
offset = offset >>> 0;
|
635
|
+
byteLength = byteLength >>> 0;
|
636
|
+
if (!noAssert) {
|
637
|
+
Buffer._checkOffset(offset, byteLength, this.length);
|
638
|
+
}
|
639
|
+
let val = this[offset];
|
640
|
+
let mul = 1;
|
641
|
+
let i = 0;
|
642
|
+
while (++i < byteLength && (mul *= 256)) {
|
643
|
+
val += this[offset + i] * mul;
|
644
|
+
}
|
645
|
+
mul *= 128;
|
646
|
+
if (val >= mul) {
|
647
|
+
val -= Math.pow(2, 8 * byteLength);
|
648
|
+
}
|
649
|
+
return val;
|
650
|
+
}
|
651
|
+
/**
|
652
|
+
* Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as a
|
653
|
+
* big-endian, two's complement signed value supporting up to 48 bits of accuracy.
|
654
|
+
*
|
655
|
+
* @param offset Number of bytes to skip before starting to read.
|
656
|
+
* @param byteLength Number of bytes to read, between 0 and 6.
|
657
|
+
* @param noAssert
|
658
|
+
*/
|
659
|
+
readIntBE(offset, byteLength, noAssert) {
|
660
|
+
offset = offset >>> 0;
|
661
|
+
byteLength = byteLength >>> 0;
|
662
|
+
if (!noAssert) {
|
663
|
+
Buffer._checkOffset(offset, byteLength, this.length);
|
664
|
+
}
|
665
|
+
let i = byteLength;
|
666
|
+
let mul = 1;
|
667
|
+
let val = this[offset + --i];
|
668
|
+
while (i > 0 && (mul *= 256)) {
|
669
|
+
val += this[offset + --i] * mul;
|
670
|
+
}
|
671
|
+
mul *= 128;
|
672
|
+
if (val >= mul) {
|
673
|
+
val -= Math.pow(2, 8 * byteLength);
|
674
|
+
}
|
675
|
+
return val;
|
676
|
+
}
|
677
|
+
/**
|
678
|
+
* Reads an unsigned 8-bit integer from `buf` at the specified `offset`.
|
679
|
+
*
|
680
|
+
* @param offset Number of bytes to skip before starting to read.
|
681
|
+
* @param noAssert
|
682
|
+
*/
|
683
|
+
readUInt8(offset, noAssert) {
|
684
|
+
offset = offset >>> 0;
|
685
|
+
if (!noAssert) {
|
686
|
+
Buffer._checkOffset(offset, 1, this.length);
|
687
|
+
}
|
688
|
+
return this[offset];
|
689
|
+
}
|
690
|
+
/**
|
691
|
+
* Reads an unsigned, little-endian 16-bit integer from `buf` at the specified `offset`.
|
692
|
+
*
|
693
|
+
* @param offset Number of bytes to skip before starting to read.
|
694
|
+
* @param noAssert
|
695
|
+
*/
|
696
|
+
readUInt16LE(offset, noAssert) {
|
697
|
+
offset = offset >>> 0;
|
698
|
+
if (!noAssert) {
|
699
|
+
Buffer._checkOffset(offset, 2, this.length);
|
700
|
+
}
|
701
|
+
return this[offset] | this[offset + 1] << 8;
|
702
|
+
}
|
703
|
+
/**
|
704
|
+
* Reads an unsigned, big-endian 16-bit integer from `buf` at the specified `offset`.
|
705
|
+
*
|
706
|
+
* @param offset Number of bytes to skip before starting to read.
|
707
|
+
* @param noAssert
|
708
|
+
*/
|
709
|
+
readUInt16BE(offset, noAssert) {
|
710
|
+
offset = offset >>> 0;
|
711
|
+
if (!noAssert) {
|
712
|
+
Buffer._checkOffset(offset, 2, this.length);
|
713
|
+
}
|
714
|
+
return this[offset] << 8 | this[offset + 1];
|
715
|
+
}
|
716
|
+
/**
|
717
|
+
* Reads an unsigned, little-endian 32-bit integer from `buf` at the specified `offset`.
|
718
|
+
*
|
719
|
+
* @param offset Number of bytes to skip before starting to read.
|
720
|
+
* @param noAssert
|
721
|
+
*/
|
722
|
+
readUInt32LE(offset, noAssert) {
|
723
|
+
offset = offset >>> 0;
|
724
|
+
if (!noAssert) {
|
725
|
+
Buffer._checkOffset(offset, 4, this.length);
|
726
|
+
}
|
727
|
+
return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216;
|
728
|
+
}
|
729
|
+
/**
|
730
|
+
* Reads an unsigned, big-endian 32-bit integer from `buf` at the specified `offset`.
|
731
|
+
*
|
732
|
+
* @param offset Number of bytes to skip before starting to read.
|
733
|
+
* @param noAssert
|
734
|
+
*/
|
735
|
+
readUInt32BE(offset, noAssert) {
|
736
|
+
offset = offset >>> 0;
|
737
|
+
if (!noAssert) {
|
738
|
+
Buffer._checkOffset(offset, 4, this.length);
|
739
|
+
}
|
740
|
+
return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
|
741
|
+
}
|
742
|
+
/**
|
743
|
+
* Reads a signed 8-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer` are interpreted
|
744
|
+
* as two's complement signed values.
|
745
|
+
*
|
746
|
+
* @param offset Number of bytes to skip before starting to read.
|
747
|
+
* @param noAssert
|
748
|
+
*/
|
749
|
+
readInt8(offset, noAssert) {
|
750
|
+
offset = offset >>> 0;
|
751
|
+
if (!noAssert) {
|
752
|
+
Buffer._checkOffset(offset, 1, this.length);
|
753
|
+
}
|
754
|
+
if (!(this[offset] & 128)) {
|
755
|
+
return this[offset];
|
756
|
+
}
|
757
|
+
return (255 - this[offset] + 1) * -1;
|
758
|
+
}
|
759
|
+
/**
|
760
|
+
* Reads a signed, little-endian 16-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer`
|
761
|
+
* are interpreted as two's complement signed values.
|
762
|
+
*
|
763
|
+
* @param offset Number of bytes to skip before starting to read.
|
764
|
+
* @param noAssert
|
765
|
+
*/
|
766
|
+
readInt16LE(offset, noAssert) {
|
767
|
+
offset = offset >>> 0;
|
768
|
+
if (!noAssert) {
|
769
|
+
Buffer._checkOffset(offset, 2, this.length);
|
770
|
+
}
|
771
|
+
const val = this[offset] | this[offset + 1] << 8;
|
772
|
+
return val & 32768 ? val | 4294901760 : val;
|
773
|
+
}
|
774
|
+
/**
|
775
|
+
* Reads a signed, big-endian 16-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer`
|
776
|
+
* are interpreted as two's complement signed values.
|
777
|
+
*
|
778
|
+
* @param offset Number of bytes to skip before starting to read.
|
779
|
+
* @param noAssert
|
780
|
+
*/
|
781
|
+
readInt16BE(offset, noAssert) {
|
782
|
+
offset = offset >>> 0;
|
783
|
+
if (!noAssert) {
|
784
|
+
Buffer._checkOffset(offset, 2, this.length);
|
785
|
+
}
|
786
|
+
const val = this[offset + 1] | this[offset] << 8;
|
787
|
+
return val & 32768 ? val | 4294901760 : val;
|
788
|
+
}
|
789
|
+
/**
|
790
|
+
* Reads a signed, little-endian 32-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer`
|
791
|
+
* are interpreted as two's complement signed values.
|
792
|
+
*
|
793
|
+
* @param offset Number of bytes to skip before starting to read.
|
794
|
+
* @param noAssert
|
795
|
+
*/
|
796
|
+
readInt32LE(offset, noAssert) {
|
797
|
+
offset = offset >>> 0;
|
798
|
+
if (!noAssert) {
|
799
|
+
Buffer._checkOffset(offset, 4, this.length);
|
800
|
+
}
|
801
|
+
return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
|
802
|
+
}
|
803
|
+
/**
|
804
|
+
* Reads a signed, big-endian 32-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer`
|
805
|
+
* are interpreted as two's complement signed values.
|
806
|
+
*
|
807
|
+
* @param offset Number of bytes to skip before starting to read.
|
808
|
+
* @param noAssert
|
809
|
+
*/
|
810
|
+
readInt32BE(offset, noAssert) {
|
811
|
+
offset = offset >>> 0;
|
812
|
+
if (!noAssert) {
|
813
|
+
Buffer._checkOffset(offset, 4, this.length);
|
814
|
+
}
|
815
|
+
return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
|
816
|
+
}
|
817
|
+
/**
|
818
|
+
* Interprets `buf` as an array of unsigned 16-bit integers and swaps the byte order in-place.
|
819
|
+
* Throws a `RangeError` if `buf.length` is not a multiple of 2.
|
820
|
+
*/
|
821
|
+
swap16() {
|
822
|
+
const len = this.length;
|
823
|
+
if (len % 2 !== 0) {
|
824
|
+
throw new RangeError("Buffer size must be a multiple of 16-bits");
|
825
|
+
}
|
826
|
+
for (let i = 0; i < len; i += 2) {
|
827
|
+
this._swap(this, i, i + 1);
|
828
|
+
}
|
829
|
+
return this;
|
830
|
+
}
|
831
|
+
/**
|
832
|
+
* Interprets `buf` as an array of unsigned 32-bit integers and swaps the byte order in-place.
|
833
|
+
* Throws a `RangeError` if `buf.length` is not a multiple of 4.
|
834
|
+
*/
|
835
|
+
swap32() {
|
836
|
+
const len = this.length;
|
837
|
+
if (len % 4 !== 0) {
|
838
|
+
throw new RangeError("Buffer size must be a multiple of 32-bits");
|
839
|
+
}
|
840
|
+
for (let i = 0; i < len; i += 4) {
|
841
|
+
this._swap(this, i, i + 3);
|
842
|
+
this._swap(this, i + 1, i + 2);
|
843
|
+
}
|
844
|
+
return this;
|
845
|
+
}
|
846
|
+
/**
|
847
|
+
* Interprets `buf` as an array of unsigned 64-bit integers and swaps the byte order in-place.
|
848
|
+
* Throws a `RangeError` if `buf.length` is not a multiple of 8.
|
849
|
+
*/
|
850
|
+
swap64() {
|
851
|
+
const len = this.length;
|
852
|
+
if (len % 8 !== 0) {
|
853
|
+
throw new RangeError("Buffer size must be a multiple of 64-bits");
|
854
|
+
}
|
855
|
+
for (let i = 0; i < len; i += 8) {
|
856
|
+
this._swap(this, i, i + 7);
|
857
|
+
this._swap(this, i + 1, i + 6);
|
858
|
+
this._swap(this, i + 2, i + 5);
|
859
|
+
this._swap(this, i + 3, i + 4);
|
860
|
+
}
|
861
|
+
return this;
|
862
|
+
}
|
863
|
+
/**
|
864
|
+
* Swaps two octets.
|
865
|
+
*
|
866
|
+
* @param b
|
867
|
+
* @param n
|
868
|
+
* @param m
|
869
|
+
*/
|
870
|
+
_swap(b, n, m) {
|
871
|
+
const i = b[n];
|
872
|
+
b[n] = b[m];
|
873
|
+
b[m] = i;
|
874
|
+
}
|
875
|
+
/**
|
876
|
+
* Writes `value` to `buf` at the specified `offset`. The `value` must be a valid unsigned 8-bit integer.
|
877
|
+
* Behavior is undefined when `value` is anything other than an unsigned 8-bit integer.
|
878
|
+
*
|
879
|
+
* @param value Number to write.
|
880
|
+
* @param offset Number of bytes to skip before starting to write.
|
881
|
+
* @param noAssert
|
882
|
+
* @returns `offset` plus the number of bytes written.
|
883
|
+
*/
|
884
|
+
writeUInt8(value, offset, noAssert) {
|
885
|
+
value = +value;
|
886
|
+
offset = offset >>> 0;
|
887
|
+
if (!noAssert) {
|
888
|
+
Buffer._checkInt(this, value, offset, 1, 255, 0);
|
889
|
+
}
|
890
|
+
this[offset] = value & 255;
|
891
|
+
return offset + 1;
|
892
|
+
}
|
893
|
+
/**
|
894
|
+
* Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a valid unsigned 16-bit
|
895
|
+
* integer. Behavior is undefined when `value` is anything other than an unsigned 16-bit integer.
|
896
|
+
*
|
897
|
+
* @param value Number to write.
|
898
|
+
* @param offset Number of bytes to skip before starting to write.
|
899
|
+
* @param noAssert
|
900
|
+
* @returns `offset` plus the number of bytes written.
|
901
|
+
*/
|
902
|
+
writeUInt16LE(value, offset, noAssert) {
|
903
|
+
value = +value;
|
904
|
+
offset = offset >>> 0;
|
905
|
+
if (!noAssert) {
|
906
|
+
Buffer._checkInt(this, value, offset, 2, 65535, 0);
|
907
|
+
}
|
908
|
+
this[offset] = value & 255;
|
909
|
+
this[offset + 1] = value >>> 8;
|
910
|
+
return offset + 2;
|
911
|
+
}
|
912
|
+
/**
|
913
|
+
* Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a valid unsigned 16-bit
|
914
|
+
* integer. Behavior is undefined when `value` is anything other than an unsigned 16-bit integer.
|
915
|
+
*
|
916
|
+
* @param value Number to write.
|
917
|
+
* @param offset Number of bytes to skip before starting to write.
|
918
|
+
* @param noAssert
|
919
|
+
* @returns `offset` plus the number of bytes written.
|
920
|
+
*/
|
921
|
+
writeUInt16BE(value, offset, noAssert) {
|
922
|
+
value = +value;
|
923
|
+
offset = offset >>> 0;
|
924
|
+
if (!noAssert) {
|
925
|
+
Buffer._checkInt(this, value, offset, 2, 65535, 0);
|
926
|
+
}
|
927
|
+
this[offset] = value >>> 8;
|
928
|
+
this[offset + 1] = value & 255;
|
929
|
+
return offset + 2;
|
930
|
+
}
|
931
|
+
/**
|
932
|
+
* Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a valid unsigned 32-bit
|
933
|
+
* integer. Behavior is undefined when `value` is anything other than an unsigned 32-bit integer.
|
934
|
+
*
|
935
|
+
* @param value Number to write.
|
936
|
+
* @param offset Number of bytes to skip before starting to write.
|
937
|
+
* @param noAssert
|
938
|
+
* @returns `offset` plus the number of bytes written.
|
939
|
+
*/
|
940
|
+
writeUInt32LE(value, offset, noAssert) {
|
941
|
+
value = +value;
|
942
|
+
offset = offset >>> 0;
|
943
|
+
if (!noAssert) {
|
944
|
+
Buffer._checkInt(this, value, offset, 4, 4294967295, 0);
|
945
|
+
}
|
946
|
+
this[offset + 3] = value >>> 24;
|
947
|
+
this[offset + 2] = value >>> 16;
|
948
|
+
this[offset + 1] = value >>> 8;
|
949
|
+
this[offset] = value & 255;
|
950
|
+
return offset + 4;
|
951
|
+
}
|
952
|
+
/**
|
953
|
+
* Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a valid unsigned 32-bit
|
954
|
+
* integer. Behavior is undefined when `value` is anything other than an unsigned 32-bit integer.
|
955
|
+
*
|
956
|
+
* @param value Number to write.
|
957
|
+
* @param offset Number of bytes to skip before starting to write.
|
958
|
+
* @param noAssert
|
959
|
+
* @returns `offset` plus the number of bytes written.
|
960
|
+
*/
|
961
|
+
writeUInt32BE(value, offset, noAssert) {
|
962
|
+
value = +value;
|
963
|
+
offset = offset >>> 0;
|
964
|
+
if (!noAssert) {
|
965
|
+
Buffer._checkInt(this, value, offset, 4, 4294967295, 0);
|
966
|
+
}
|
967
|
+
this[offset] = value >>> 24;
|
968
|
+
this[offset + 1] = value >>> 16;
|
969
|
+
this[offset + 2] = value >>> 8;
|
970
|
+
this[offset + 3] = value & 255;
|
971
|
+
return offset + 4;
|
972
|
+
}
|
973
|
+
/**
|
974
|
+
* Writes `value` to `buf` at the specified `offset`. The `value` must be a valid signed 8-bit integer.
|
975
|
+
* Behavior is undefined when `value` is anything other than a signed 8-bit integer.
|
976
|
+
*
|
977
|
+
* @param value Number to write.
|
978
|
+
* @param offset Number of bytes to skip before starting to write.
|
979
|
+
* @param noAssert
|
980
|
+
* @returns `offset` plus the number of bytes written.
|
981
|
+
*/
|
982
|
+
writeInt8(value, offset, noAssert) {
|
983
|
+
value = +value;
|
984
|
+
offset = offset >>> 0;
|
985
|
+
if (!noAssert) {
|
986
|
+
Buffer._checkInt(this, value, offset, 1, 127, -128);
|
987
|
+
}
|
988
|
+
if (value < 0) {
|
989
|
+
value = 255 + value + 1;
|
990
|
+
}
|
991
|
+
this[offset] = value & 255;
|
992
|
+
return offset + 1;
|
993
|
+
}
|
994
|
+
/**
|
995
|
+
* Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a valid signed 16-bit
|
996
|
+
* integer. Behavior is undefined when `value` is anything other than a signed 16-bit integer.
|
997
|
+
*
|
998
|
+
* @param value Number to write.
|
999
|
+
* @param offset Number of bytes to skip before starting to write.
|
1000
|
+
* @param noAssert
|
1001
|
+
* @returns `offset` plus the number of bytes written.
|
1002
|
+
*/
|
1003
|
+
writeInt16LE(value, offset, noAssert) {
|
1004
|
+
value = +value;
|
1005
|
+
offset = offset >>> 0;
|
1006
|
+
if (!noAssert) {
|
1007
|
+
Buffer._checkInt(this, value, offset, 2, 32767, -32768);
|
1008
|
+
}
|
1009
|
+
this[offset] = value & 255;
|
1010
|
+
this[offset + 1] = value >>> 8;
|
1011
|
+
return offset + 2;
|
1012
|
+
}
|
1013
|
+
/**
|
1014
|
+
* Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a valid signed 16-bit
|
1015
|
+
* integer. Behavior is undefined when `value` is anything other than a signed 16-bit integer.
|
1016
|
+
*
|
1017
|
+
* @param value Number to write.
|
1018
|
+
* @param offset Number of bytes to skip before starting to write.
|
1019
|
+
* @param noAssert
|
1020
|
+
* @returns `offset` plus the number of bytes written.
|
1021
|
+
*/
|
1022
|
+
writeInt16BE(value, offset, noAssert) {
|
1023
|
+
value = +value;
|
1024
|
+
offset = offset >>> 0;
|
1025
|
+
if (!noAssert) {
|
1026
|
+
Buffer._checkInt(this, value, offset, 2, 32767, -32768);
|
1027
|
+
}
|
1028
|
+
this[offset] = value >>> 8;
|
1029
|
+
this[offset + 1] = value & 255;
|
1030
|
+
return offset + 2;
|
1031
|
+
}
|
1032
|
+
/**
|
1033
|
+
* Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a valid signed 32-bit
|
1034
|
+
* integer. Behavior is undefined when `value` is anything other than a signed 32-bit integer.
|
1035
|
+
*
|
1036
|
+
* @param value Number to write.
|
1037
|
+
* @param offset Number of bytes to skip before starting to write.
|
1038
|
+
* @param noAssert
|
1039
|
+
* @returns `offset` plus the number of bytes written.
|
1040
|
+
*/
|
1041
|
+
writeInt32LE(value, offset, noAssert) {
|
1042
|
+
value = +value;
|
1043
|
+
offset = offset >>> 0;
|
1044
|
+
if (!noAssert) {
|
1045
|
+
Buffer._checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
1046
|
+
}
|
1047
|
+
this[offset] = value & 255;
|
1048
|
+
this[offset + 1] = value >>> 8;
|
1049
|
+
this[offset + 2] = value >>> 16;
|
1050
|
+
this[offset + 3] = value >>> 24;
|
1051
|
+
return offset + 4;
|
1052
|
+
}
|
1053
|
+
/**
|
1054
|
+
* Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a valid signed 32-bit
|
1055
|
+
* integer. Behavior is undefined when `value` is anything other than a signed 32-bit integer.
|
1056
|
+
*
|
1057
|
+
* @param value Number to write.
|
1058
|
+
* @param offset Number of bytes to skip before starting to write.
|
1059
|
+
* @param noAssert
|
1060
|
+
* @returns `offset` plus the number of bytes written.
|
1061
|
+
*/
|
1062
|
+
writeInt32BE(value, offset, noAssert) {
|
1063
|
+
value = +value;
|
1064
|
+
offset = offset >>> 0;
|
1065
|
+
if (!noAssert) {
|
1066
|
+
Buffer._checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
1067
|
+
}
|
1068
|
+
if (value < 0) {
|
1069
|
+
value = 4294967295 + value + 1;
|
1070
|
+
}
|
1071
|
+
this[offset] = value >>> 24;
|
1072
|
+
this[offset + 1] = value >>> 16;
|
1073
|
+
this[offset + 2] = value >>> 8;
|
1074
|
+
this[offset + 3] = value & 255;
|
1075
|
+
return offset + 4;
|
1076
|
+
}
|
1077
|
+
/**
|
1078
|
+
* Fills `buf` with the specified `value`. If the `offset` and `end` are not given, the entire `buf` will be
|
1079
|
+
* filled. The `value` is coerced to a `uint32` value if it is not a string, `Buffer`, or integer. If the resulting
|
1080
|
+
* integer is greater than `255` (decimal), then `buf` will be filled with `value & 255`.
|
1081
|
+
*
|
1082
|
+
* If the final write of a `fill()` operation falls on a multi-byte character, then only the bytes of that
|
1083
|
+
* character that fit into `buf` are written.
|
1084
|
+
*
|
1085
|
+
* If `value` contains invalid characters, it is truncated; if no valid fill data remains, an exception is thrown.
|
1086
|
+
*
|
1087
|
+
* @param value
|
1088
|
+
* @param encoding
|
1089
|
+
*/
|
1090
|
+
fill(value, offset, end, encoding) {
|
1091
|
+
if (typeof value === "string") {
|
1092
|
+
if (typeof offset === "string") {
|
1093
|
+
encoding = offset;
|
1094
|
+
offset = 0;
|
1095
|
+
end = this.length;
|
1096
|
+
} else if (typeof end === "string") {
|
1097
|
+
encoding = end;
|
1098
|
+
end = this.length;
|
1099
|
+
}
|
1100
|
+
if (encoding !== void 0 && typeof encoding !== "string") {
|
1101
|
+
throw new TypeError("encoding must be a string");
|
1102
|
+
}
|
1103
|
+
if (typeof encoding === "string" && !Buffer.isEncoding(encoding)) {
|
1104
|
+
throw new TypeError("Unknown encoding: " + encoding);
|
1105
|
+
}
|
1106
|
+
if (value.length === 1) {
|
1107
|
+
const code = value.charCodeAt(0);
|
1108
|
+
if (encoding === "utf8" && code < 128) {
|
1109
|
+
value = code;
|
1110
|
+
}
|
1111
|
+
}
|
1112
|
+
} else if (typeof value === "number") {
|
1113
|
+
value = value & 255;
|
1114
|
+
} else if (typeof value === "boolean") {
|
1115
|
+
value = Number(value);
|
1116
|
+
}
|
1117
|
+
offset ?? (offset = 0);
|
1118
|
+
end ?? (end = this.length);
|
1119
|
+
if (offset < 0 || this.length < offset || this.length < end) {
|
1120
|
+
throw new RangeError("Out of range index");
|
1121
|
+
}
|
1122
|
+
if (end <= offset) {
|
1123
|
+
return this;
|
1124
|
+
}
|
1125
|
+
offset = offset >>> 0;
|
1126
|
+
end = end === void 0 ? this.length : end >>> 0;
|
1127
|
+
value || (value = 0);
|
1128
|
+
let i;
|
1129
|
+
if (typeof value === "number") {
|
1130
|
+
for (i = offset; i < end; ++i) {
|
1131
|
+
this[i] = value;
|
1132
|
+
}
|
1133
|
+
} else {
|
1134
|
+
const bytes = Buffer.isBuffer(value) ? value : Buffer.from(value, encoding);
|
1135
|
+
const len = bytes.length;
|
1136
|
+
if (len === 0) {
|
1137
|
+
throw new TypeError('The value "' + value + '" is invalid for argument "value"');
|
1138
|
+
}
|
1139
|
+
for (i = 0; i < end - offset; ++i) {
|
1140
|
+
this[i + offset] = bytes[i % len];
|
1141
|
+
}
|
1142
|
+
}
|
1143
|
+
return this;
|
1144
|
+
}
|
1145
|
+
/**
|
1146
|
+
* Returns the index of the specified value.
|
1147
|
+
*
|
1148
|
+
* If `value` is:
|
1149
|
+
* - a string, `value` is interpreted according to the character encoding in `encoding`.
|
1150
|
+
* - a `Buffer` or `Uint8Array`, `value` will be used in its entirety. To compare a partial Buffer, use `slice()`.
|
1151
|
+
* - a number, `value` will be interpreted as an unsigned 8-bit integer value between `0` and `255`.
|
1152
|
+
*
|
1153
|
+
* Any other types will throw a `TypeError`.
|
1154
|
+
*
|
1155
|
+
* @param value What to search for.
|
1156
|
+
* @param byteOffset Where to begin searching in `buf`. If negative, then calculated from the end.
|
1157
|
+
* @param encoding If `value` is a string, this is the encoding used to search.
|
1158
|
+
* @returns The index of the first occurrence of `value` in `buf`, or `-1` if not found.
|
1159
|
+
*/
|
1160
|
+
indexOf(value, byteOffset, encoding) {
|
1161
|
+
return this._bidirectionalIndexOf(this, value, byteOffset, encoding, true);
|
1162
|
+
}
|
1163
|
+
/**
|
1164
|
+
* Gets the last index of the specified value.
|
1165
|
+
*
|
1166
|
+
* @see indexOf()
|
1167
|
+
* @param value
|
1168
|
+
* @param byteOffset
|
1169
|
+
* @param encoding
|
1170
|
+
*/
|
1171
|
+
lastIndexOf(value, byteOffset, encoding) {
|
1172
|
+
return this._bidirectionalIndexOf(this, value, byteOffset, encoding, false);
|
1173
|
+
}
|
1174
|
+
_bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
|
1175
|
+
if (buffer.length === 0) {
|
1176
|
+
return -1;
|
1177
|
+
}
|
1178
|
+
if (typeof byteOffset === "string") {
|
1179
|
+
encoding = byteOffset;
|
1180
|
+
byteOffset = 0;
|
1181
|
+
} else if (typeof byteOffset === "undefined") {
|
1182
|
+
byteOffset = 0;
|
1183
|
+
} else if (byteOffset > 2147483647) {
|
1184
|
+
byteOffset = 2147483647;
|
1185
|
+
} else if (byteOffset < -2147483648) {
|
1186
|
+
byteOffset = -2147483648;
|
1187
|
+
}
|
1188
|
+
byteOffset = +byteOffset;
|
1189
|
+
if (byteOffset !== byteOffset) {
|
1190
|
+
byteOffset = dir ? 0 : buffer.length - 1;
|
1191
|
+
}
|
1192
|
+
if (byteOffset < 0) {
|
1193
|
+
byteOffset = buffer.length + byteOffset;
|
1194
|
+
}
|
1195
|
+
if (byteOffset >= buffer.length) {
|
1196
|
+
if (dir) {
|
1197
|
+
return -1;
|
1198
|
+
} else {
|
1199
|
+
byteOffset = buffer.length - 1;
|
1200
|
+
}
|
1201
|
+
} else if (byteOffset < 0) {
|
1202
|
+
if (dir) {
|
1203
|
+
byteOffset = 0;
|
1204
|
+
} else {
|
1205
|
+
return -1;
|
1206
|
+
}
|
1207
|
+
}
|
1208
|
+
if (typeof val === "string") {
|
1209
|
+
val = Buffer.from(val, encoding);
|
1210
|
+
}
|
1211
|
+
if (Buffer.isBuffer(val)) {
|
1212
|
+
if (val.length === 0) {
|
1213
|
+
return -1;
|
1214
|
+
}
|
1215
|
+
return Buffer._arrayIndexOf(buffer, val, byteOffset, encoding, dir);
|
1216
|
+
} else if (typeof val === "number") {
|
1217
|
+
val = val & 255;
|
1218
|
+
if (typeof Uint8Array.prototype.indexOf === "function") {
|
1219
|
+
if (dir) {
|
1220
|
+
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
|
1221
|
+
} else {
|
1222
|
+
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
|
1223
|
+
}
|
1224
|
+
}
|
1225
|
+
return Buffer._arrayIndexOf(buffer, Buffer.from([val]), byteOffset, encoding, dir);
|
1226
|
+
}
|
1227
|
+
throw new TypeError("val must be string, number or Buffer");
|
1228
|
+
}
|
1229
|
+
/**
|
1230
|
+
* Equivalent to `buf.indexOf() !== -1`.
|
1231
|
+
*
|
1232
|
+
* @param value
|
1233
|
+
* @param byteOffset
|
1234
|
+
* @param encoding
|
1235
|
+
*/
|
1236
|
+
includes(value, byteOffset, encoding) {
|
1237
|
+
return this.indexOf(value, byteOffset, encoding) !== -1;
|
1238
|
+
}
|
1239
|
+
/**
|
1240
|
+
* Creates a new buffer from the given parameters.
|
1241
|
+
*
|
1242
|
+
* @param data
|
1243
|
+
* @param encoding
|
1244
|
+
*/
|
1245
|
+
static from(a, b, c) {
|
1246
|
+
return new Buffer(a, b, c);
|
1247
|
+
}
|
1248
|
+
/**
|
1249
|
+
* Returns true if `obj` is a Buffer.
|
1250
|
+
*
|
1251
|
+
* @param obj
|
1252
|
+
*/
|
1253
|
+
static isBuffer(obj) {
|
1254
|
+
return obj != null && obj !== Buffer.prototype && Buffer._isInstance(obj, Buffer);
|
1255
|
+
}
|
1256
|
+
/**
|
1257
|
+
* Returns true if `encoding` is a supported encoding.
|
1258
|
+
*
|
1259
|
+
* @param encoding
|
1260
|
+
*/
|
1261
|
+
static isEncoding(encoding) {
|
1262
|
+
switch (encoding.toLowerCase()) {
|
1263
|
+
case "hex":
|
1264
|
+
case "utf8":
|
1265
|
+
case "ascii":
|
1266
|
+
case "binary":
|
1267
|
+
case "latin1":
|
1268
|
+
case "ucs2":
|
1269
|
+
case "utf16le":
|
1270
|
+
case "base64":
|
1271
|
+
return true;
|
1272
|
+
default:
|
1273
|
+
return false;
|
1274
|
+
}
|
1275
|
+
}
|
1276
|
+
/**
|
1277
|
+
* Gives the actual byte length of a string for an encoding. This is not the same as `string.length` since that
|
1278
|
+
* returns the number of characters in the string.
|
1279
|
+
*
|
1280
|
+
* @param string The string to test.
|
1281
|
+
* @param encoding The encoding to use for calculation. Defaults is `utf8`.
|
1282
|
+
*/
|
1283
|
+
static byteLength(string, encoding) {
|
1284
|
+
if (Buffer.isBuffer(string)) {
|
1285
|
+
return string.length;
|
1286
|
+
}
|
1287
|
+
if (typeof string !== "string" && (ArrayBuffer.isView(string) || Buffer._isInstance(string, ArrayBuffer))) {
|
1288
|
+
return string.byteLength;
|
1289
|
+
}
|
1290
|
+
if (typeof string !== "string") {
|
1291
|
+
throw new TypeError(
|
1292
|
+
'The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type ' + typeof string
|
1293
|
+
);
|
1294
|
+
}
|
1295
|
+
const len = string.length;
|
1296
|
+
const mustMatch = arguments.length > 2 && arguments[2] === true;
|
1297
|
+
if (!mustMatch && len === 0) {
|
1298
|
+
return 0;
|
1299
|
+
}
|
1300
|
+
switch (encoding?.toLowerCase()) {
|
1301
|
+
case "ascii":
|
1302
|
+
case "latin1":
|
1303
|
+
case "binary":
|
1304
|
+
return len;
|
1305
|
+
case "utf8":
|
1306
|
+
return Buffer._utf8ToBytes(string).length;
|
1307
|
+
case "hex":
|
1308
|
+
return len >>> 1;
|
1309
|
+
case "ucs2":
|
1310
|
+
case "utf16le":
|
1311
|
+
return len * 2;
|
1312
|
+
case "base64":
|
1313
|
+
return Buffer._base64ToBytes(string).length;
|
1314
|
+
default:
|
1315
|
+
return mustMatch ? -1 : Buffer._utf8ToBytes(string).length;
|
1316
|
+
}
|
1317
|
+
}
|
1318
|
+
/**
|
1319
|
+
* Returns a Buffer which is the result of concatenating all the buffers in the list together.
|
1320
|
+
*
|
1321
|
+
* - If the list has no items, or if the `totalLength` is 0, then it returns a zero-length buffer.
|
1322
|
+
* - If the list has exactly one item, then the first item is returned.
|
1323
|
+
* - If the list has more than one item, then a new buffer is created.
|
1324
|
+
*
|
1325
|
+
* It is faster to provide the `totalLength` if it is known. However, it will be calculated if not provided at
|
1326
|
+
* a small computational expense.
|
1327
|
+
*
|
1328
|
+
* @param list An array of Buffer objects to concatenate.
|
1329
|
+
* @param totalLength Total length of the buffers when concatenated.
|
1330
|
+
*/
|
1331
|
+
static concat(list, totalLength) {
|
1332
|
+
if (!Array.isArray(list)) {
|
1333
|
+
throw new TypeError('"list" argument must be an Array of Buffers');
|
1334
|
+
}
|
1335
|
+
if (list.length === 0) {
|
1336
|
+
return Buffer.alloc(0);
|
1337
|
+
}
|
1338
|
+
let i;
|
1339
|
+
if (totalLength === void 0) {
|
1340
|
+
totalLength = 0;
|
1341
|
+
for (i = 0; i < list.length; ++i) {
|
1342
|
+
totalLength += list[i].length;
|
1343
|
+
}
|
1344
|
+
}
|
1345
|
+
const buffer = Buffer.allocUnsafe(totalLength);
|
1346
|
+
let pos = 0;
|
1347
|
+
for (i = 0; i < list.length; ++i) {
|
1348
|
+
let buf = list[i];
|
1349
|
+
if (Buffer._isInstance(buf, Uint8Array)) {
|
1350
|
+
if (pos + buf.length > buffer.length) {
|
1351
|
+
if (!Buffer.isBuffer(buf)) {
|
1352
|
+
buf = Buffer.from(buf);
|
1353
|
+
}
|
1354
|
+
buf.copy(buffer, pos);
|
1355
|
+
} else {
|
1356
|
+
Uint8Array.prototype.set.call(buffer, buf, pos);
|
1357
|
+
}
|
1358
|
+
} else if (!Buffer.isBuffer(buf)) {
|
1359
|
+
throw new TypeError('"list" argument must be an Array of Buffers');
|
1360
|
+
} else {
|
1361
|
+
buf.copy(buffer, pos);
|
1362
|
+
}
|
1363
|
+
pos += buf.length;
|
1364
|
+
}
|
1365
|
+
return buffer;
|
1366
|
+
}
|
1367
|
+
/**
|
1368
|
+
* The same as `buf1.compare(buf2)`.
|
1369
|
+
*/
|
1370
|
+
static compare(buf1, buf2) {
|
1371
|
+
if (Buffer._isInstance(buf1, Uint8Array)) {
|
1372
|
+
buf1 = Buffer.from(buf1, buf1.byteOffset, buf1.byteLength);
|
1373
|
+
}
|
1374
|
+
if (Buffer._isInstance(buf2, Uint8Array)) {
|
1375
|
+
buf2 = Buffer.from(buf2, buf2.byteOffset, buf2.byteLength);
|
1376
|
+
}
|
1377
|
+
if (!Buffer.isBuffer(buf1) || !Buffer.isBuffer(buf2)) {
|
1378
|
+
throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');
|
1379
|
+
}
|
1380
|
+
if (buf1 === buf2) {
|
1381
|
+
return 0;
|
1382
|
+
}
|
1383
|
+
let x = buf1.length;
|
1384
|
+
let y = buf2.length;
|
1385
|
+
for (let i = 0, len = Math.min(x, y); i < len; ++i) {
|
1386
|
+
if (buf1[i] !== buf2[i]) {
|
1387
|
+
x = buf1[i];
|
1388
|
+
y = buf2[i];
|
1389
|
+
break;
|
1390
|
+
}
|
1391
|
+
}
|
1392
|
+
if (x < y) {
|
1393
|
+
return -1;
|
1394
|
+
}
|
1395
|
+
if (y < x) {
|
1396
|
+
return 1;
|
1397
|
+
}
|
1398
|
+
return 0;
|
1399
|
+
}
|
1400
|
+
/**
|
1401
|
+
* Allocates a new buffer of `size` octets.
|
1402
|
+
*
|
1403
|
+
* @param size The number of octets to allocate.
|
1404
|
+
* @param fill If specified, the buffer will be initialized by calling `buf.fill(fill)`, or with zeroes otherwise.
|
1405
|
+
* @param encoding The encoding used for the call to `buf.fill()` while initializing.
|
1406
|
+
*/
|
1407
|
+
static alloc(size, fill, encoding) {
|
1408
|
+
if (typeof size !== "number") {
|
1409
|
+
throw new TypeError('"size" argument must be of type number');
|
1410
|
+
} else if (size < 0) {
|
1411
|
+
throw new RangeError('The value "' + size + '" is invalid for option "size"');
|
1412
|
+
}
|
1413
|
+
if (size <= 0) {
|
1414
|
+
return new Buffer(size);
|
1415
|
+
}
|
1416
|
+
if (fill !== void 0) {
|
1417
|
+
return typeof encoding === "string" ? new Buffer(size).fill(fill, 0, size, encoding) : new Buffer(size).fill(fill);
|
1418
|
+
}
|
1419
|
+
return new Buffer(size);
|
1420
|
+
}
|
1421
|
+
/**
|
1422
|
+
* Allocates a new buffer of `size` octets without initializing memory. The contents of the buffer are unknown.
|
1423
|
+
*
|
1424
|
+
* @param size
|
1425
|
+
*/
|
1426
|
+
static allocUnsafe(size) {
|
1427
|
+
if (typeof size !== "number") {
|
1428
|
+
throw new TypeError('"size" argument must be of type number');
|
1429
|
+
} else if (size < 0) {
|
1430
|
+
throw new RangeError('The value "' + size + '" is invalid for option "size"');
|
1431
|
+
}
|
1432
|
+
return new Buffer(size < 0 ? 0 : Buffer._checked(size) | 0);
|
1433
|
+
}
|
1434
|
+
/**
|
1435
|
+
* Returns true if the given `obj` is an instance of `type`.
|
1436
|
+
*
|
1437
|
+
* @param obj
|
1438
|
+
* @param type
|
1439
|
+
*/
|
1440
|
+
static _isInstance(obj, type) {
|
1441
|
+
return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;
|
1442
|
+
}
|
1443
|
+
static _checked(length) {
|
1444
|
+
if (length >= K_MAX_LENGTH) {
|
1445
|
+
throw new RangeError(
|
1446
|
+
"Attempt to allocate Buffer larger than maximum size: 0x" + K_MAX_LENGTH.toString(16) + " bytes"
|
1447
|
+
);
|
1448
|
+
}
|
1449
|
+
return length | 0;
|
1450
|
+
}
|
1451
|
+
static _blitBuffer(src, dst, offset, length) {
|
1452
|
+
let i;
|
1453
|
+
for (i = 0; i < length; ++i) {
|
1454
|
+
if (i + offset >= dst.length || i >= src.length) {
|
1455
|
+
break;
|
1456
|
+
}
|
1457
|
+
dst[i + offset] = src[i];
|
1458
|
+
}
|
1459
|
+
return i;
|
1460
|
+
}
|
1461
|
+
static _utf8Write(buf, string, offset, length) {
|
1462
|
+
return Buffer._blitBuffer(Buffer._utf8ToBytes(string, buf.length - offset), buf, offset, length);
|
1463
|
+
}
|
1464
|
+
static _asciiWrite(buf, string, offset, length) {
|
1465
|
+
return Buffer._blitBuffer(Buffer._asciiToBytes(string), buf, offset, length);
|
1466
|
+
}
|
1467
|
+
static _base64Write(buf, string, offset, length) {
|
1468
|
+
return Buffer._blitBuffer(Buffer._base64ToBytes(string), buf, offset, length);
|
1469
|
+
}
|
1470
|
+
static _ucs2Write(buf, string, offset, length) {
|
1471
|
+
return Buffer._blitBuffer(Buffer._utf16leToBytes(string, buf.length - offset), buf, offset, length);
|
1472
|
+
}
|
1473
|
+
static _hexWrite(buf, string, offset, length) {
|
1474
|
+
offset = Number(offset) || 0;
|
1475
|
+
const remaining = buf.length - offset;
|
1476
|
+
if (!length) {
|
1477
|
+
length = remaining;
|
1478
|
+
} else {
|
1479
|
+
length = Number(length);
|
1480
|
+
if (length > remaining) {
|
1481
|
+
length = remaining;
|
1482
|
+
}
|
1483
|
+
}
|
1484
|
+
const strLen = string.length;
|
1485
|
+
if (length > strLen / 2) {
|
1486
|
+
length = strLen / 2;
|
1487
|
+
}
|
1488
|
+
let i;
|
1489
|
+
for (i = 0; i < length; ++i) {
|
1490
|
+
const parsed = parseInt(string.substr(i * 2, 2), 16);
|
1491
|
+
if (parsed !== parsed) {
|
1492
|
+
return i;
|
1493
|
+
}
|
1494
|
+
buf[offset + i] = parsed;
|
1495
|
+
}
|
1496
|
+
return i;
|
1497
|
+
}
|
1498
|
+
static _utf8ToBytes(string, units) {
|
1499
|
+
units = units || Infinity;
|
1500
|
+
const length = string.length;
|
1501
|
+
const bytes = [];
|
1502
|
+
let codePoint;
|
1503
|
+
let leadSurrogate = null;
|
1504
|
+
for (let i = 0; i < length; ++i) {
|
1505
|
+
codePoint = string.charCodeAt(i);
|
1506
|
+
if (codePoint > 55295 && codePoint < 57344) {
|
1507
|
+
if (!leadSurrogate) {
|
1508
|
+
if (codePoint > 56319) {
|
1509
|
+
if ((units -= 3) > -1) {
|
1510
|
+
bytes.push(239, 191, 189);
|
1511
|
+
}
|
1512
|
+
continue;
|
1513
|
+
} else if (i + 1 === length) {
|
1514
|
+
if ((units -= 3) > -1) {
|
1515
|
+
bytes.push(239, 191, 189);
|
1516
|
+
}
|
1517
|
+
continue;
|
1518
|
+
}
|
1519
|
+
leadSurrogate = codePoint;
|
1520
|
+
continue;
|
1521
|
+
}
|
1522
|
+
if (codePoint < 56320) {
|
1523
|
+
if ((units -= 3) > -1) {
|
1524
|
+
bytes.push(239, 191, 189);
|
1525
|
+
}
|
1526
|
+
leadSurrogate = codePoint;
|
1527
|
+
continue;
|
1528
|
+
}
|
1529
|
+
codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536;
|
1530
|
+
} else if (leadSurrogate) {
|
1531
|
+
if ((units -= 3) > -1) {
|
1532
|
+
bytes.push(239, 191, 189);
|
1533
|
+
}
|
1534
|
+
}
|
1535
|
+
leadSurrogate = null;
|
1536
|
+
if (codePoint < 128) {
|
1537
|
+
if ((units -= 1) < 0) {
|
1538
|
+
break;
|
1539
|
+
}
|
1540
|
+
bytes.push(codePoint);
|
1541
|
+
} else if (codePoint < 2048) {
|
1542
|
+
if ((units -= 2) < 0) {
|
1543
|
+
break;
|
1544
|
+
}
|
1545
|
+
bytes.push(codePoint >> 6 | 192, codePoint & 63 | 128);
|
1546
|
+
} else if (codePoint < 65536) {
|
1547
|
+
if ((units -= 3) < 0) {
|
1548
|
+
break;
|
1549
|
+
}
|
1550
|
+
bytes.push(codePoint >> 12 | 224, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);
|
1551
|
+
} else if (codePoint < 1114112) {
|
1552
|
+
if ((units -= 4) < 0) {
|
1553
|
+
break;
|
1554
|
+
}
|
1555
|
+
bytes.push(
|
1556
|
+
codePoint >> 18 | 240,
|
1557
|
+
codePoint >> 12 & 63 | 128,
|
1558
|
+
codePoint >> 6 & 63 | 128,
|
1559
|
+
codePoint & 63 | 128
|
1560
|
+
);
|
1561
|
+
} else {
|
1562
|
+
throw new Error("Invalid code point");
|
1563
|
+
}
|
1564
|
+
}
|
1565
|
+
return bytes;
|
1566
|
+
}
|
1567
|
+
static _base64ToBytes(str) {
|
1568
|
+
return toByteArray(base64clean(str));
|
1569
|
+
}
|
1570
|
+
static _asciiToBytes(str) {
|
1571
|
+
const byteArray = [];
|
1572
|
+
for (let i = 0; i < str.length; ++i) {
|
1573
|
+
byteArray.push(str.charCodeAt(i) & 255);
|
1574
|
+
}
|
1575
|
+
return byteArray;
|
1576
|
+
}
|
1577
|
+
static _utf16leToBytes(str, units) {
|
1578
|
+
let c, hi, lo;
|
1579
|
+
const byteArray = [];
|
1580
|
+
for (let i = 0; i < str.length; ++i) {
|
1581
|
+
if ((units -= 2) < 0)
|
1582
|
+
break;
|
1583
|
+
c = str.charCodeAt(i);
|
1584
|
+
hi = c >> 8;
|
1585
|
+
lo = c % 256;
|
1586
|
+
byteArray.push(lo);
|
1587
|
+
byteArray.push(hi);
|
1588
|
+
}
|
1589
|
+
return byteArray;
|
1590
|
+
}
|
1591
|
+
static _hexSlice(buf, start, end) {
|
1592
|
+
const len = buf.length;
|
1593
|
+
if (!start || start < 0) {
|
1594
|
+
start = 0;
|
1595
|
+
}
|
1596
|
+
if (!end || end < 0 || end > len) {
|
1597
|
+
end = len;
|
1598
|
+
}
|
1599
|
+
let out = "";
|
1600
|
+
for (let i = start; i < end; ++i) {
|
1601
|
+
out += hexSliceLookupTable[buf[i]];
|
1602
|
+
}
|
1603
|
+
return out;
|
1604
|
+
}
|
1605
|
+
static _base64Slice(buf, start, end) {
|
1606
|
+
if (start === 0 && end === buf.length) {
|
1607
|
+
return fromByteArray(buf);
|
1608
|
+
} else {
|
1609
|
+
return fromByteArray(buf.slice(start, end));
|
1610
|
+
}
|
1611
|
+
}
|
1612
|
+
static _utf8Slice(buf, start, end) {
|
1613
|
+
end = Math.min(buf.length, end);
|
1614
|
+
const res = [];
|
1615
|
+
let i = start;
|
1616
|
+
while (i < end) {
|
1617
|
+
const firstByte = buf[i];
|
1618
|
+
let codePoint = null;
|
1619
|
+
let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
|
1620
|
+
if (i + bytesPerSequence <= end) {
|
1621
|
+
let secondByte, thirdByte, fourthByte, tempCodePoint;
|
1622
|
+
switch (bytesPerSequence) {
|
1623
|
+
case 1:
|
1624
|
+
if (firstByte < 128) {
|
1625
|
+
codePoint = firstByte;
|
1626
|
+
}
|
1627
|
+
break;
|
1628
|
+
case 2:
|
1629
|
+
secondByte = buf[i + 1];
|
1630
|
+
if ((secondByte & 192) === 128) {
|
1631
|
+
tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;
|
1632
|
+
if (tempCodePoint > 127) {
|
1633
|
+
codePoint = tempCodePoint;
|
1634
|
+
}
|
1635
|
+
}
|
1636
|
+
break;
|
1637
|
+
case 3:
|
1638
|
+
secondByte = buf[i + 1];
|
1639
|
+
thirdByte = buf[i + 2];
|
1640
|
+
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {
|
1641
|
+
tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;
|
1642
|
+
if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) {
|
1643
|
+
codePoint = tempCodePoint;
|
1644
|
+
}
|
1645
|
+
}
|
1646
|
+
break;
|
1647
|
+
case 4:
|
1648
|
+
secondByte = buf[i + 1];
|
1649
|
+
thirdByte = buf[i + 2];
|
1650
|
+
fourthByte = buf[i + 3];
|
1651
|
+
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
|
1652
|
+
tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;
|
1653
|
+
if (tempCodePoint > 65535 && tempCodePoint < 1114112) {
|
1654
|
+
codePoint = tempCodePoint;
|
1655
|
+
}
|
1656
|
+
}
|
1657
|
+
}
|
1658
|
+
}
|
1659
|
+
if (codePoint === null) {
|
1660
|
+
codePoint = 65533;
|
1661
|
+
bytesPerSequence = 1;
|
1662
|
+
} else if (codePoint > 65535) {
|
1663
|
+
codePoint -= 65536;
|
1664
|
+
res.push(codePoint >>> 10 & 1023 | 55296);
|
1665
|
+
codePoint = 56320 | codePoint & 1023;
|
1666
|
+
}
|
1667
|
+
res.push(codePoint);
|
1668
|
+
i += bytesPerSequence;
|
1669
|
+
}
|
1670
|
+
return Buffer._decodeCodePointsArray(res);
|
1671
|
+
}
|
1672
|
+
static _decodeCodePointsArray(codePoints) {
|
1673
|
+
const len = codePoints.length;
|
1674
|
+
if (len <= MAX_ARGUMENTS_LENGTH) {
|
1675
|
+
return String.fromCharCode.apply(String, codePoints);
|
1676
|
+
}
|
1677
|
+
let res = "";
|
1678
|
+
let i = 0;
|
1679
|
+
while (i < len) {
|
1680
|
+
res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH));
|
1681
|
+
}
|
1682
|
+
return res;
|
1683
|
+
}
|
1684
|
+
static _asciiSlice(buf, start, end) {
|
1685
|
+
let ret = "";
|
1686
|
+
end = Math.min(buf.length, end);
|
1687
|
+
for (let i = start; i < end; ++i) {
|
1688
|
+
ret += String.fromCharCode(buf[i] & 127);
|
1689
|
+
}
|
1690
|
+
return ret;
|
1691
|
+
}
|
1692
|
+
static _latin1Slice(buf, start, end) {
|
1693
|
+
let ret = "";
|
1694
|
+
end = Math.min(buf.length, end);
|
1695
|
+
for (let i = start; i < end; ++i) {
|
1696
|
+
ret += String.fromCharCode(buf[i]);
|
1697
|
+
}
|
1698
|
+
return ret;
|
1699
|
+
}
|
1700
|
+
static _utf16leSlice(buf, start, end) {
|
1701
|
+
const bytes = buf.slice(start, end);
|
1702
|
+
let res = "";
|
1703
|
+
for (let i = 0; i < bytes.length - 1; i += 2) {
|
1704
|
+
res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
|
1705
|
+
}
|
1706
|
+
return res;
|
1707
|
+
}
|
1708
|
+
static _arrayIndexOf(arr, val, byteOffset, encoding, dir) {
|
1709
|
+
let indexSize = 1;
|
1710
|
+
let arrLength = arr.length;
|
1711
|
+
let valLength = val.length;
|
1712
|
+
if (encoding !== void 0) {
|
1713
|
+
encoding = Buffer._getEncoding(encoding);
|
1714
|
+
if (encoding === "ucs2" || encoding === "utf16le") {
|
1715
|
+
if (arr.length < 2 || val.length < 2) {
|
1716
|
+
return -1;
|
1717
|
+
}
|
1718
|
+
indexSize = 2;
|
1719
|
+
arrLength /= 2;
|
1720
|
+
valLength /= 2;
|
1721
|
+
byteOffset /= 2;
|
1722
|
+
}
|
1723
|
+
}
|
1724
|
+
function read(buf, i2) {
|
1725
|
+
if (indexSize === 1) {
|
1726
|
+
return buf[i2];
|
1727
|
+
} else {
|
1728
|
+
return buf.readUInt16BE(i2 * indexSize);
|
1729
|
+
}
|
1730
|
+
}
|
1731
|
+
let i;
|
1732
|
+
if (dir) {
|
1733
|
+
let foundIndex = -1;
|
1734
|
+
for (i = byteOffset; i < arrLength; i++) {
|
1735
|
+
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
1736
|
+
if (foundIndex === -1)
|
1737
|
+
foundIndex = i;
|
1738
|
+
if (i - foundIndex + 1 === valLength)
|
1739
|
+
return foundIndex * indexSize;
|
1740
|
+
} else {
|
1741
|
+
if (foundIndex !== -1)
|
1742
|
+
i -= i - foundIndex;
|
1743
|
+
foundIndex = -1;
|
1744
|
+
}
|
1745
|
+
}
|
1746
|
+
} else {
|
1747
|
+
if (byteOffset + valLength > arrLength) {
|
1748
|
+
byteOffset = arrLength - valLength;
|
1749
|
+
}
|
1750
|
+
for (i = byteOffset; i >= 0; i--) {
|
1751
|
+
let found = true;
|
1752
|
+
for (let j = 0; j < valLength; j++) {
|
1753
|
+
if (read(arr, i + j) !== read(val, j)) {
|
1754
|
+
found = false;
|
1755
|
+
break;
|
1756
|
+
}
|
1757
|
+
}
|
1758
|
+
if (found) {
|
1759
|
+
return i;
|
1760
|
+
}
|
1761
|
+
}
|
1762
|
+
}
|
1763
|
+
return -1;
|
1764
|
+
}
|
1765
|
+
static _checkOffset(offset, ext, length) {
|
1766
|
+
if (offset % 1 !== 0 || offset < 0)
|
1767
|
+
throw new RangeError("offset is not uint");
|
1768
|
+
if (offset + ext > length)
|
1769
|
+
throw new RangeError("Trying to access beyond buffer length");
|
1770
|
+
}
|
1771
|
+
static _checkInt(buf, value, offset, ext, max, min) {
|
1772
|
+
if (!Buffer.isBuffer(buf))
|
1773
|
+
throw new TypeError('"buffer" argument must be a Buffer instance');
|
1774
|
+
if (value > max || value < min)
|
1775
|
+
throw new RangeError('"value" argument is out of bounds');
|
1776
|
+
if (offset + ext > buf.length)
|
1777
|
+
throw new RangeError("Index out of range");
|
1778
|
+
}
|
1779
|
+
static _getEncoding(encoding) {
|
1780
|
+
let toLowerCase = false;
|
1781
|
+
let originalEncoding = "";
|
1782
|
+
for (; ; ) {
|
1783
|
+
switch (encoding) {
|
1784
|
+
case "hex":
|
1785
|
+
return "hex";
|
1786
|
+
case "utf8":
|
1787
|
+
return "utf8";
|
1788
|
+
case "ascii":
|
1789
|
+
return "ascii";
|
1790
|
+
case "binary":
|
1791
|
+
return "binary";
|
1792
|
+
case "latin1":
|
1793
|
+
return "latin1";
|
1794
|
+
case "ucs2":
|
1795
|
+
return "ucs2";
|
1796
|
+
case "utf16le":
|
1797
|
+
return "utf16le";
|
1798
|
+
case "base64":
|
1799
|
+
return "base64";
|
1800
|
+
default: {
|
1801
|
+
if (toLowerCase) {
|
1802
|
+
throw new TypeError("Unknown or unsupported encoding: " + originalEncoding);
|
1803
|
+
}
|
1804
|
+
toLowerCase = true;
|
1805
|
+
originalEncoding = encoding;
|
1806
|
+
encoding = encoding.toLowerCase();
|
1807
|
+
}
|
1808
|
+
}
|
1809
|
+
}
|
1810
|
+
}
|
1811
|
+
}
|
1812
|
+
const hexSliceLookupTable = function() {
|
1813
|
+
const alphabet = "0123456789abcdef";
|
1814
|
+
const table = new Array(256);
|
1815
|
+
for (let i = 0; i < 16; ++i) {
|
1816
|
+
const i16 = i * 16;
|
1817
|
+
for (let j = 0; j < 16; ++j) {
|
1818
|
+
table[i16 + j] = alphabet[i] + alphabet[j];
|
1819
|
+
}
|
1820
|
+
}
|
1821
|
+
return table;
|
1822
|
+
}();
|
1823
|
+
const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
|
1824
|
+
function base64clean(str) {
|
1825
|
+
str = str.split("=")[0];
|
1826
|
+
str = str.trim().replace(INVALID_BASE64_RE, "");
|
1827
|
+
if (str.length < 2)
|
1828
|
+
return "";
|
1829
|
+
while (str.length % 4 !== 0) {
|
1830
|
+
str = str + "=";
|
1831
|
+
}
|
1832
|
+
return str;
|
1833
|
+
}
|
1834
|
+
|
27
1835
|
function notEmpty(value) {
|
28
1836
|
return value !== null && value !== void 0;
|
29
1837
|
}
|
@@ -528,7 +2336,7 @@ function defaultOnOpen(response) {
|
|
528
2336
|
}
|
529
2337
|
}
|
530
2338
|
|
531
|
-
const VERSION = "0.29.
|
2339
|
+
const VERSION = "0.29.4";
|
532
2340
|
|
533
2341
|
class ErrorWithCause extends Error {
|
534
2342
|
constructor(message, options) {
|
@@ -624,7 +2432,7 @@ function parseWorkspacesUrlParts(url) {
|
|
624
2432
|
production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh\/db\/([^:]+):?(.*)?/),
|
625
2433
|
staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev\/db\/([^:]+):?(.*)?/),
|
626
2434
|
dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev\/db\/([^:]+):?(.*)?/),
|
627
|
-
local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:([^:]+):?(.*)?/)
|
2435
|
+
local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:(?:\d+)\/db\/([^:]+):?(.*)?/)
|
628
2436
|
};
|
629
2437
|
const [host, match] = Object.entries(matches).find(([, match2]) => match2 !== null) ?? [];
|
630
2438
|
if (!isHostProviderAlias(host) || !match)
|
@@ -854,6 +2662,12 @@ const adaptTable = (variables, signal) => dataPlaneFetch({
|
|
854
2662
|
...variables,
|
855
2663
|
signal
|
856
2664
|
});
|
2665
|
+
const adaptAllTables = (variables, signal) => dataPlaneFetch({
|
2666
|
+
url: "/db/{dbBranchName}/migrations/adapt",
|
2667
|
+
method: "post",
|
2668
|
+
...variables,
|
2669
|
+
signal
|
2670
|
+
});
|
857
2671
|
const getBranchMigrationJobStatus = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/status", method: "get", ...variables, signal });
|
858
2672
|
const getMigrationJobStatus = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/jobs/{jobId}", method: "get", ...variables, signal });
|
859
2673
|
const getMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/history", method: "get", ...variables, signal });
|
@@ -1086,6 +2900,7 @@ const operationsByTag$2 = {
|
|
1086
2900
|
migrations: {
|
1087
2901
|
applyMigration,
|
1088
2902
|
adaptTable,
|
2903
|
+
adaptAllTables,
|
1089
2904
|
getBranchMigrationJobStatus,
|
1090
2905
|
getMigrationJobStatus,
|
1091
2906
|
getMigrationHistory,
|
@@ -4891,6 +6706,7 @@ class XataError extends Error {
|
|
4891
6706
|
}
|
4892
6707
|
|
4893
6708
|
exports.BaseClient = BaseClient;
|
6709
|
+
exports.Buffer = Buffer;
|
4894
6710
|
exports.FetcherError = FetcherError;
|
4895
6711
|
exports.FilesPlugin = FilesPlugin;
|
4896
6712
|
exports.Operations = operationsByTag;
|
@@ -4917,6 +6733,7 @@ exports.XataError = XataError;
|
|
4917
6733
|
exports.XataFile = XataFile;
|
4918
6734
|
exports.XataPlugin = XataPlugin;
|
4919
6735
|
exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
6736
|
+
exports.adaptAllTables = adaptAllTables;
|
4920
6737
|
exports.adaptTable = adaptTable;
|
4921
6738
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
4922
6739
|
exports.addTableColumn = addTableColumn;
|