@xata.io/client
Version:
Xata.io SDK for TypeScript and JavaScript
1 lines • 702 kB
Source Map (JSON)
{"version":3,"file":"index.cjs","sources":["../src/schema/tracing.ts","../src/util/base64.ts","../src/util/buffer.ts","../src/util/lang.ts","../src/util/environment.ts","../src/util/fetch.ts","../src/util/uuid.ts","../src/util/sse.ts","../src/version.ts","../src/api/errors.ts","../src/api/providers.ts","../src/api/fetcher.ts","../src/api/dataPlaneFetcher.ts","../src/api/dataPlaneComponents.ts","../src/api/controlPlaneFetcher.ts","../src/api/controlPlaneComponents.ts","../src/api/components.ts","../src/api/client.ts","../src/api/index.ts","../src/plugins.ts","../src/files/transformations.ts","../src/schema/files.ts","../src/schema/filters.ts","../src/schema/json.ts","../src/schema/pagination.ts","../src/schema/query.ts","../src/schema/record.ts","../src/schema/selection.ts","../src/schema/sorting.ts","../src/schema/repository.ts","../src/schema/cache.ts","../src/schema/operators.ts","../src/schema/index.ts","../src/files/index.ts","../src/search/index.ts","../src/sql/parameters.ts","../src/sql/index.ts","../src/transaction/index.ts","../src/client.ts","../src/serializer/index.ts","../src/index.ts"],"sourcesContent":["export type AttributeDictionary = Record<string, string | number | boolean | undefined>;\n\nexport type TraceFunction = <T>(\n name: string,\n fn: (options: { name?: string; setAttributes: (attrs: AttributeDictionary) => void }) => T,\n options?: AttributeDictionary\n) => Promise<T>;\n\nexport const defaultTrace: TraceFunction = async <T>(\n name: string,\n fn: (options: {\n name?: string;\n setAttributes: (attrs: Record<string, string | number | boolean | undefined>) => void;\n }) => T,\n _options?: Record<string, any>\n): Promise<T> => {\n return await fn({\n name,\n setAttributes: () => {\n return;\n }\n });\n};\n\nexport const TraceAttributes = {\n KIND: 'xata.trace.kind',\n\n VERSION: 'xata.sdk.version',\n\n TABLE: 'xata.table',\n\n HTTP_REQUEST_ID: 'http.request_id',\n HTTP_STATUS_CODE: 'http.status_code',\n HTTP_HOST: 'http.host',\n HTTP_SCHEME: 'http.scheme',\n HTTP_USER_AGENT: 'http.user_agent',\n HTTP_METHOD: 'http.method',\n HTTP_URL: 'http.url',\n HTTP_ROUTE: 'http.route',\n HTTP_TARGET: 'http.target',\n\n CLOUDFLARE_RAY_ID: 'cf.ray'\n};\n","// Based from https://github.com/beatgammit/base64-js\n\nconst lookup: string[] = [];\nconst revLookup: number[] = [];\n\nconst code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\nfor (let i = 0, len = code.length; i < len; ++i) {\n lookup[i] = code[i];\n revLookup[code.charCodeAt(i)] = i;\n}\n\n// Support decoding URL-safe base64 strings, as Node.js does.\n// See: https://en.wikipedia.org/wiki/Base64#URL_applications\nrevLookup['-'.charCodeAt(0)] = 62;\nrevLookup['_'.charCodeAt(0)] = 63;\n\nfunction getLens(b64: string) {\n const len = b64.length;\n\n if (len % 4 > 0) {\n throw new Error('Invalid string. Length must be a multiple of 4');\n }\n\n // Trim off extra bytes after placeholder bytes are found\n // See: https://github.com/beatgammit/base64-js/issues/42\n let validLen = b64.indexOf('=');\n if (validLen === -1) validLen = len;\n\n const placeHoldersLen = validLen === len ? 0 : 4 - (validLen % 4);\n\n return [validLen, placeHoldersLen];\n}\n\n// base64 is 4/3 + up to two characters of the original data\nexport function byteLength(b64: string): number {\n const lens = getLens(b64);\n const validLen = lens[0];\n const placeHoldersLen = lens[1];\n return ((validLen + placeHoldersLen) * 3) / 4 - placeHoldersLen;\n}\n\nfunction _byteLength(_b64: string, validLen: number, placeHoldersLen: number): number {\n return ((validLen + placeHoldersLen) * 3) / 4 - placeHoldersLen;\n}\n\nexport function toByteArray(b64: string): Uint8Array {\n let tmp;\n const lens = getLens(b64);\n const validLen = lens[0];\n const placeHoldersLen = lens[1];\n\n const arr = new Uint8Array(_byteLength(b64, validLen, placeHoldersLen));\n\n let curByte = 0;\n\n // if there are placeholders, only get up to the last complete 4 chars\n const len = placeHoldersLen > 0 ? validLen - 4 : validLen;\n\n let i;\n for (i = 0; i < len; i += 4) {\n tmp =\n (revLookup[b64.charCodeAt(i)] << 18) |\n (revLookup[b64.charCodeAt(i + 1)] << 12) |\n (revLookup[b64.charCodeAt(i + 2)] << 6) |\n revLookup[b64.charCodeAt(i + 3)];\n arr[curByte++] = (tmp >> 16) & 0xff;\n arr[curByte++] = (tmp >> 8) & 0xff;\n arr[curByte++] = tmp & 0xff;\n }\n\n if (placeHoldersLen === 2) {\n tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4);\n arr[curByte++] = tmp & 0xff;\n }\n\n if (placeHoldersLen === 1) {\n tmp =\n (revLookup[b64.charCodeAt(i)] << 10) |\n (revLookup[b64.charCodeAt(i + 1)] << 4) |\n (revLookup[b64.charCodeAt(i + 2)] >> 2);\n arr[curByte++] = (tmp >> 8) & 0xff;\n arr[curByte++] = tmp & 0xff;\n }\n\n return arr;\n}\n\nfunction tripletToBase64(num: number): string {\n return lookup[(num >> 18) & 0x3f] + lookup[(num >> 12) & 0x3f] + lookup[(num >> 6) & 0x3f] + lookup[num & 0x3f];\n}\n\nfunction encodeChunk(uint8: Uint8Array | number[], start: number, end: number): string {\n let tmp;\n const output = [];\n for (let i = start; i < end; i += 3) {\n tmp = ((uint8[i] << 16) & 0xff0000) + ((uint8[i + 1] << 8) & 0xff00) + (uint8[i + 2] & 0xff);\n output.push(tripletToBase64(tmp));\n }\n return output.join('');\n}\n\nexport function fromByteArray(uint8: Uint8Array | number[]): string {\n let tmp;\n const len = uint8.length;\n const extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes\n const parts = [];\n const maxChunkLength = 16383; // must be multiple of 3\n\n // go through the array every three bytes, we'll deal with trailing stuff later\n for (let i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {\n parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength));\n }\n\n // pad the end with zeros, but make sure to not forget the extra bytes\n if (extraBytes === 1) {\n tmp = uint8[len - 1];\n parts.push(lookup[tmp >> 2] + lookup[(tmp << 4) & 0x3f] + '==');\n } else if (extraBytes === 2) {\n tmp = (uint8[len - 2] << 8) + uint8[len - 1];\n parts.push(lookup[tmp >> 10] + lookup[(tmp >> 4) & 0x3f] + lookup[(tmp << 2) & 0x3f] + '=');\n }\n\n return parts.join('');\n}\n","/* eslint-disable prefer-rest-params, prefer-spread */\n\nimport * as base64 from './base64';\n\nexport const K_MAX_LENGTH = 0x7fffffff;\nexport const MAX_ARGUMENTS_LENGTH = 4096;\n\n// Based from https://github.com/feross/buffer\n// Re-used some type checking from https://gist.github.com/baileyherbert/799c9277429497a40c5f28599494d46f\nclass Buffer extends Uint8Array {\n /**\n * Allocates a new buffer containing the given `str`.\n *\n * @param str String to store in buffer.\n * @param encoding Encoding to use, optional. Default is `utf8`.\n */\n constructor(str: string, encoding?: Encoding);\n\n /**\n * Allocates a new buffer of `size` octets.\n *\n * @param size Count of octets to allocate.\n */\n constructor(size: number);\n\n /**\n * Allocates a new buffer containing the given `array` of octets.\n *\n * @param array The octets to store.\n */\n constructor(array: Uint8Array);\n\n /**\n * Allocates a new buffer containing the given `array` of octet values.\n *\n * @param array\n */\n constructor(array: number[]);\n\n /**\n * Allocates a new buffer containing the given `array` of octet values.\n *\n * @param array\n * @param encoding\n */\n constructor(array: number[], encoding: Encoding);\n\n /**\n * Copies the passed `buffer` data onto a new `Buffer` instance.\n *\n * @param buffer\n */\n constructor(buffer: Buffer);\n\n /**\n * When passed a reference to the .buffer property of a TypedArray instance, the newly created Buffer will share\n * the same allocated memory as the TypedArray. The optional `byteOffset` and `length` arguments specify a memory\n * range within the `arrayBuffer` that will be shared by the Buffer.\n *\n * @param buffer The .buffer property of a TypedArray or a new ArrayBuffer().\n * @param byteOffset\n * @param length\n */\n constructor(buffer: ArrayBuffer, byteOffset?: number, length?: number);\n\n /**\n * Constructs a new `Buffer` instance.\n *\n * @param value\n * @param encodingOrOffset\n * @param length\n */\n constructor(\n value: string | number | Uint8Array | ArrayBuffer | number[] | Buffer,\n encodingOrOffset?: Encoding | number,\n length?: number\n ) {\n // Handle numbers\n if (typeof value === 'number') {\n // If the value is a number but an encoding was provided, there's a mistake -- throw an error\n if (typeof encodingOrOffset === 'string') {\n throw new TypeError('The first argument must be of type string, received type number');\n }\n\n // Make sure it's positive!!\n if (value < 0) {\n throw new RangeError('The buffer size cannot be negative');\n }\n\n super(value < 0 ? 0 : Buffer._checked(value) | 0);\n }\n\n // Handle strings\n else if (typeof value === 'string') {\n if (typeof encodingOrOffset !== 'string') {\n encodingOrOffset = 'utf8';\n }\n\n if (!Buffer.isEncoding(encodingOrOffset)) {\n throw new TypeError('Unknown encoding: ' + encodingOrOffset);\n }\n\n // Create the internal buffer\n const length = Buffer.byteLength(value, encodingOrOffset) | 0;\n super(length);\n\n // Write the data\n // We'll also make sure the expected number of bytes was written\n // If not, something is wrong somewhere, and instead of ignoring it we should error!\n const written = this.write(value, 0, this.length, encodingOrOffset);\n\n if (written !== length) {\n throw new TypeError(\n 'Number of bytes written did not match expected length (wrote ' + written + ', expected ' + length + ')'\n );\n }\n }\n\n // Handle views\n else if (ArrayBuffer.isView(value)) {\n // Create from a direct view\n if (Buffer._isInstance(value, Uint8Array)) {\n const copy = new Uint8Array(value);\n const array = copy.buffer;\n const byteOffset = copy.byteOffset;\n const length = copy.byteLength;\n\n if (byteOffset < 0 || array.byteLength < byteOffset) {\n throw new RangeError('offset is outside of buffer bounds');\n }\n\n if (array.byteLength < byteOffset + (length || 0)) {\n throw new RangeError('length is outside of buffer bounds');\n }\n\n // Create from the array buffer\n super(new Uint8Array(array, byteOffset, length));\n }\n\n // Create from an array like\n else {\n const array = value as ArrayLike<number>;\n const length = array.length < 0 ? 0 : Buffer._checked(array.length) | 0;\n\n // Create the buffer\n super(new Uint8Array(length));\n\n // Allocate the bytes manually\n for (let i = 0; i < length; i++) {\n this[i] = array[i] & 255;\n }\n }\n }\n\n // Handle falsey values\n else if (value == null) {\n throw new TypeError(\n 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +\n 'or Array-like Object. Received type ' +\n typeof value\n );\n }\n\n // Handle array buffers\n else if (\n Buffer._isInstance(value, ArrayBuffer) ||\n (value && Buffer._isInstance((value as any).buffer, ArrayBuffer))\n ) {\n const array = value as Uint8Array;\n const byteOffset = encodingOrOffset as number;\n\n if (byteOffset < 0 || array.byteLength < byteOffset) {\n throw new RangeError('offset is outside of buffer bounds');\n }\n\n if (array.byteLength < byteOffset + (length || 0)) {\n throw new RangeError('length is outside of buffer bounds');\n }\n\n // Create from the array buffer\n super(new Uint8Array(array, byteOffset, length));\n }\n\n // Handle arrays\n else if (Array.isArray(value)) {\n const array = value as ArrayLike<number>;\n const length = array.length < 0 ? 0 : Buffer._checked(array.length) | 0;\n\n // Create the buffer\n super(new Uint8Array(length));\n\n // Allocate the bytes manually\n for (let i = 0; i < length; i++) {\n this[i] = array[i] & 255;\n }\n }\n\n // Throw an error for anything else\n else {\n throw new TypeError('Unable to determine the correct way to allocate buffer for type ' + typeof value);\n }\n }\n\n /**\n * Return JSON representation of the buffer.\n */\n public toJSON(): { type: 'Buffer'; data: number[] } {\n return {\n type: 'Buffer',\n data: Array.prototype.slice.call(this)\n };\n }\n\n /**\n * Writes `string` to the buffer at `offset` according to the character encoding in `encoding`. The `length`\n * parameter is the number of bytes to write. If the buffer does not contain enough space to fit the entire string,\n * only part of `string` will be written. However, partially encoded characters will not be written.\n *\n * @param string String to write to `buf`.\n * @param encoding The character encoding of `string`. Default: `utf8`.\n */\n public write(string: string, encoding?: Encoding): number;\n\n /**\n * Writes `string` to the buffer at `offset` according to the character encoding in `encoding`. The `length`\n * parameter is the number of bytes to write. If the buffer does not contain enough space to fit the entire string,\n * only part of `string` will be written. However, partially encoded characters will not be written.\n *\n * @param string String to write to `buf`.\n * @param offset Number of bytes to skip before starting to write `string`. Default: `0`.\n * @param length Maximum number of bytes to write: Default: `buf.length - offset`.\n * @param encoding The character encoding of `string`. Default: `utf8`.\n */\n public write(string: string, offset?: number, length?: number, encoding?: Encoding): number;\n\n /**\n * Writes `string` to the buffer at `offset` according to the character encoding in `encoding`. The `length`\n * parameter is the number of bytes to write. If the buffer does not contain enough space to fit the entire string,\n * only part of `string` will be written. However, partially encoded characters will not be written.\n *\n * @param string String to write to `buf`.\n * @param offset Number of bytes to skip before starting to write `string`. Default: `0`.\n * @param length Maximum number of bytes to write: Default: `buf.length - offset`.\n * @param encoding The character encoding of `string`. Default: `utf8`.\n */\n public write(string: string, offset?: number | Encoding, length?: number, encoding?: Encoding): number {\n if (typeof offset === 'undefined') {\n encoding = 'utf8';\n length = this.length;\n offset = 0;\n } else if (typeof length === 'undefined' && typeof offset === 'string') {\n encoding = offset;\n length = this.length;\n offset = 0;\n } else if (typeof offset === 'number' && isFinite(offset)) {\n offset = offset >>> 0;\n\n if (typeof length === 'number' && isFinite(length)) {\n length = length >>> 0;\n encoding ??= 'utf8';\n } else if (typeof length === 'string') {\n encoding = length;\n length = undefined;\n }\n // else {\n // \tthrow new TypeError('Error forming arguments');\n // }\n } else {\n throw new Error('Buffer.write(string, encoding, offset[, length]) is no longer supported');\n }\n\n const remaining = this.length - offset;\n\n if (typeof length === 'undefined' || length > remaining) {\n length = remaining;\n }\n\n if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {\n throw new RangeError('Attempt to write outside buffer bounds');\n }\n\n // Default encoding to utf8\n encoding ||= 'utf8';\n\n switch (Buffer._getEncoding(encoding)) {\n case 'hex':\n return Buffer._hexWrite(this, string, offset, length);\n\n case 'utf8':\n return Buffer._utf8Write(this, string, offset, length);\n\n case 'ascii':\n case 'latin1':\n case 'binary':\n return Buffer._asciiWrite(this, string, offset, length);\n\n case 'ucs2':\n case 'utf16le':\n return Buffer._ucs2Write(this, string, offset, length);\n\n case 'base64':\n return Buffer._base64Write(this, string, offset, length);\n }\n }\n\n /**\n * Decodes the buffer to a string according to the specified character encoding.\n * Passing `start` and `end` will decode only a subset of the buffer.\n *\n * Note that if the encoding is `utf8` and a byte sequence in the input is not valid UTF-8, then each invalid byte\n * will be replaced with `U+FFFD`.\n *\n * @param encoding\n * @param start\n * @param end\n */\n public toString(encoding?: Encoding, start?: number, end?: number): string {\n const length = this.length;\n\n if (length === 0) {\n return '';\n }\n\n if (arguments.length === 0) {\n return Buffer._utf8Slice(this, 0, length);\n }\n\n if (typeof start === 'undefined' || start < 0) {\n start = 0;\n }\n\n if (start > this.length) {\n return '';\n }\n\n if (typeof end === 'undefined' || end > this.length) {\n end = this.length;\n }\n\n if (end <= 0) {\n return '';\n }\n\n // Force coercion to uint32, this will also convert falsey valves to 0\n end >>>= 0;\n start >>>= 0;\n\n if (end <= start) {\n return '';\n }\n\n if (!encoding) {\n encoding = 'utf8';\n }\n\n switch (Buffer._getEncoding(encoding)) {\n case 'hex':\n return Buffer._hexSlice(this, start, end);\n\n case 'utf8':\n return Buffer._utf8Slice(this, start, end);\n\n case 'ascii':\n return Buffer._asciiSlice(this, start, end);\n\n case 'latin1':\n case 'binary':\n return Buffer._latin1Slice(this, start, end);\n\n case 'ucs2':\n case 'utf16le':\n return Buffer._utf16leSlice(this, start, end);\n\n case 'base64':\n return Buffer._base64Slice(this, start, end);\n }\n }\n\n /**\n * Returns true if this buffer's is equal to the provided buffer, meaning they share the same exact data.\n *\n * @param otherBuffer\n */\n public equals(otherBuffer: Buffer): boolean {\n if (!Buffer.isBuffer(otherBuffer)) {\n throw new TypeError('Argument must be a Buffer');\n }\n\n if (this === otherBuffer) {\n return true;\n }\n\n return Buffer.compare(this, otherBuffer) === 0;\n }\n\n /**\n * Compares the buffer with `otherBuffer` and returns a number indicating whether the buffer comes before, after,\n * or is the same as `otherBuffer` in sort order. Comparison is based on the actual sequence of bytes in each\n * buffer.\n *\n * - `0` is returned if `otherBuffer` is the same as this buffer.\n * - `1` is returned if `otherBuffer` should come before this buffer when sorted.\n * - `-1` is returned if `otherBuffer` should come after this buffer when sorted.\n *\n * @param otherBuffer The buffer to compare to.\n * @param targetStart The offset within `otherBuffer` at which to begin comparison.\n * @param targetEnd The offset within `otherBuffer` at which to end comparison (exclusive).\n * @param sourceStart The offset within this buffer at which to begin comparison.\n * @param sourceEnd The offset within this buffer at which to end the comparison (exclusive).\n */\n public compare(\n otherBuffer: Uint8Array,\n targetStart?: number,\n targetEnd?: number,\n sourceStart?: number,\n sourceEnd?: number\n ): number {\n if (Buffer._isInstance(otherBuffer, Uint8Array)) {\n otherBuffer = Buffer.from(otherBuffer, otherBuffer.byteOffset, otherBuffer.byteLength);\n }\n\n if (!Buffer.isBuffer(otherBuffer)) {\n throw new TypeError('Argument must be a Buffer or Uint8Array');\n }\n\n targetStart ??= 0;\n targetEnd ??= otherBuffer ? otherBuffer.length : 0;\n sourceStart ??= 0;\n sourceEnd ??= this.length;\n\n if (targetStart < 0 || targetEnd > otherBuffer.length || sourceStart < 0 || sourceEnd > this.length) {\n throw new RangeError('Out of range index');\n }\n\n if (sourceStart >= sourceEnd && targetStart >= targetEnd) {\n return 0;\n }\n\n if (sourceStart >= sourceEnd) {\n return -1;\n }\n\n if (targetStart >= targetEnd) {\n return 1;\n }\n\n targetStart >>>= 0;\n targetEnd >>>= 0;\n sourceStart >>>= 0;\n sourceEnd >>>= 0;\n\n if (this === otherBuffer) {\n return 0;\n }\n\n let x = sourceEnd - sourceStart;\n let y = targetEnd - targetStart;\n const len = Math.min(x, y);\n\n const thisCopy = this.slice(sourceStart, sourceEnd);\n const targetCopy = otherBuffer.slice(targetStart, targetEnd);\n\n for (let i = 0; i < len; ++i) {\n if (thisCopy[i] !== targetCopy[i]) {\n x = thisCopy[i];\n y = targetCopy[i];\n\n break;\n }\n }\n\n if (x < y) return -1;\n if (y < x) return 1;\n\n return 0;\n }\n\n /**\n * Copies data from a region of this buffer to a region in `targetBuffer`, even if the `targetBuffer` memory\n * region overlaps with this buffer.\n *\n * @param targetBuffer The target buffer to copy into.\n * @param targetStart The offset within `targetBuffer` at which to begin writing.\n * @param sourceStart The offset within this buffer at which to begin copying.\n * @param sourceEnd The offset within this buffer at which to end copying (exclusive).\n */\n public copy(targetBuffer: Uint8Array, targetStart?: number, sourceStart?: number, sourceEnd?: number): number {\n if (!Buffer.isBuffer(targetBuffer)) throw new TypeError('argument should be a Buffer');\n if (!sourceStart) sourceStart = 0;\n if (!targetStart) targetStart = 0;\n if (!sourceEnd && sourceEnd !== 0) sourceEnd = this.length;\n if (targetStart >= targetBuffer.length) targetStart = targetBuffer.length;\n if (!targetStart) targetStart = 0;\n if (sourceEnd > 0 && sourceEnd < sourceStart) sourceEnd = sourceStart;\n\n // Copy 0 bytes; we're done\n if (sourceEnd === sourceStart) return 0;\n if (targetBuffer.length === 0 || this.length === 0) return 0;\n\n // Fatal error conditions\n if (targetStart < 0) {\n throw new RangeError('targetStart out of bounds');\n }\n\n if (sourceStart < 0 || sourceStart >= this.length) throw new RangeError('Index out of range');\n if (sourceEnd < 0) throw new RangeError('sourceEnd out of bounds');\n\n // Are we oob?\n if (sourceEnd > this.length) sourceEnd = this.length;\n if (targetBuffer.length - targetStart < sourceEnd - sourceStart) {\n sourceEnd = targetBuffer.length - targetStart + sourceStart;\n }\n\n const len = sourceEnd - sourceStart;\n\n if (this === targetBuffer && typeof Uint8Array.prototype.copyWithin === 'function') {\n // Use built-in when available, missing from IE11\n this.copyWithin(targetStart, sourceStart, sourceEnd);\n } else {\n Uint8Array.prototype.set.call(targetBuffer, this.subarray(sourceStart, sourceEnd), targetStart);\n }\n\n return len;\n }\n\n /**\n * Returns a new `Buffer` that references the same memory as the original, but offset and cropped by the `start`\n * and `end` indices. This is the same behavior as `buf.subarray()`.\n *\n * This method is not compatible with the `Uint8Array.prototype.slice()`, which is a superclass of Buffer. To copy\n * the slice, use `Uint8Array.prototype.slice()`.\n *\n * @param start\n * @param end\n */\n public slice(start?: number, end?: number): Buffer {\n if (!start) {\n start = 0;\n }\n\n const len = this.length;\n start = ~~start;\n end = end === undefined ? len : ~~end;\n\n if (start < 0) {\n start += len;\n\n if (start < 0) {\n start = 0;\n }\n } else if (start > len) {\n start = len;\n }\n\n if (end < 0) {\n end += len;\n\n if (end < 0) {\n end = 0;\n }\n } else if (end > len) {\n end = len;\n }\n\n if (end < start) {\n end = start;\n }\n\n const newBuf = this.subarray(start, end);\n\n // Return an augmented `Uint8Array` instance\n Object.setPrototypeOf(newBuf, Buffer.prototype);\n\n return newBuf as Buffer;\n }\n\n /**\n * Writes `byteLength` bytes of `value` to `buf` at the specified `offset` as little-endian. Supports up to 48 bits\n * of accuracy. Behavior is undefined when value is anything other than an unsigned integer.\n *\n * @param value Number to write.\n * @param offset Number of bytes to skip before starting to write.\n * @param byteLength Number of bytes to write, between 0 and 6.\n * @param noAssert\n * @returns `offset` plus the number of bytes written.\n */\n public writeUIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number {\n value = +value;\n offset = offset >>> 0;\n byteLength = byteLength >>> 0;\n\n if (!noAssert) {\n const maxBytes = Math.pow(2, 8 * byteLength) - 1;\n Buffer._checkInt(this, value, offset, byteLength, maxBytes, 0);\n }\n\n let mul = 1;\n let i = 0;\n\n this[offset] = value & 0xff;\n\n while (++i < byteLength && (mul *= 0x100)) {\n this[offset + i] = (value / mul) & 0xff;\n }\n\n return offset + byteLength;\n }\n\n /**\n * Writes `byteLength` bytes of `value` to `buf` at the specified `offset` as big-endian. Supports up to 48 bits of\n * accuracy. Behavior is undefined when `value` is anything other than an unsigned integer.\n *\n * @param value Number to write.\n * @param offset Number of bytes to skip before starting to write.\n * @param byteLength Number of bytes to write, between 0 and 6.\n * @param noAssert\n * @returns `offset` plus the number of bytes written.\n */\n public writeUIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number {\n value = +value;\n offset = offset >>> 0;\n byteLength = byteLength >>> 0;\n\n if (!noAssert) {\n const maxBytes = Math.pow(2, 8 * byteLength) - 1;\n Buffer._checkInt(this, value, offset, byteLength, maxBytes, 0);\n }\n\n let i = byteLength - 1;\n let mul = 1;\n\n this[offset + i] = value & 0xff;\n\n while (--i >= 0 && (mul *= 0x100)) {\n this[offset + i] = (value / mul) & 0xff;\n }\n\n return offset + byteLength;\n }\n\n /**\n * Writes `byteLength` bytes of `value` to `buf` at the specified `offset` as little-endian. Supports up to 48 bits\n * of accuracy. Behavior is undefined when `value` is anything other than a signed integer.\n *\n * @param value Number to write.\n * @param offset Number of bytes to skip before starting to write.\n * @param byteLength Number of bytes to write, between 0 and 6.\n * @param noAssert\n * @returns `offset` plus the number of bytes written.\n */\n public writeIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number {\n value = +value;\n offset = offset >>> 0;\n\n if (!noAssert) {\n const limit = Math.pow(2, 8 * byteLength - 1);\n Buffer._checkInt(this, value, offset, byteLength, limit - 1, -limit);\n }\n\n let i = 0;\n let mul = 1;\n let sub = 0;\n\n this[offset] = value & 0xff;\n\n while (++i < byteLength && (mul *= 0x100)) {\n if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {\n sub = 1;\n }\n\n this[offset + i] = (((value / mul) >> 0) - sub) & 0xff;\n }\n\n return offset + byteLength;\n }\n\n /**\n * Writes `byteLength` bytes of `value` to `buf` at the specified `offset` as big-endian. Supports up to 48 bits\n * of accuracy. Behavior is undefined when `value` is anything other than a signed integer.\n *\n * @param value Number to write.\n * @param offset Number of bytes to skip before starting to write.\n * @param byteLength Number of bytes to write, between 0 and 6.\n * @param noAssert\n * @returns `offset` plus the number of bytes written.\n */\n public writeIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number {\n value = +value;\n offset = offset >>> 0;\n\n if (!noAssert) {\n const limit = Math.pow(2, 8 * byteLength - 1);\n Buffer._checkInt(this, value, offset, byteLength, limit - 1, -limit);\n }\n\n let i = byteLength - 1;\n let mul = 1;\n let sub = 0;\n\n this[offset + i] = value & 0xff;\n\n while (--i >= 0 && (mul *= 0x100)) {\n if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {\n sub = 1;\n }\n\n this[offset + i] = (((value / mul) >> 0) - sub) & 0xff;\n }\n\n return offset + byteLength;\n }\n\n /**\n * Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as an\n * unsigned, little-endian integer supporting up to 48 bits of accuracy.\n *\n * @param offset Number of bytes to skip before starting to read.\n * @param byteLength Number of bytes to read, between 0 and 6.\n * @param noAssert\n */\n public readUIntLE(offset: number, byteLength: number, noAssert?: boolean): number {\n offset = offset >>> 0;\n byteLength = byteLength >>> 0;\n\n if (!noAssert) {\n Buffer._checkOffset(offset, byteLength, this.length);\n }\n\n let val = this[offset];\n let mul = 1;\n let i = 0;\n\n while (++i < byteLength && (mul *= 0x100)) {\n val += this[offset + i] * mul;\n }\n\n return val;\n }\n\n /**\n * Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as an\n * unsigned, big-endian integer supporting up to 48 bits of accuracy.\n *\n * @param offset Number of bytes to skip before starting to read.\n * @param byteLength Number of bytes to read, between 0 and 6.\n * @param noAssert\n */\n public readUIntBE(offset: number, byteLength: number, noAssert?: boolean): number {\n offset = offset >>> 0;\n byteLength = byteLength >>> 0;\n\n if (!noAssert) {\n Buffer._checkOffset(offset, byteLength, this.length);\n }\n\n let val = this[offset + --byteLength];\n let mul = 1;\n\n while (byteLength > 0 && (mul *= 0x100)) {\n val += this[offset + --byteLength] * mul;\n }\n\n return val;\n }\n\n /**\n * Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as a\n * little-endian, two's complement signed value supporting up to 48 bits of accuracy.\n *\n * @param offset Number of bytes to skip before starting to read.\n * @param byteLength Number of bytes to read, between 0 and 6.\n * @param noAssert\n */\n public readIntLE(offset: number, byteLength: number, noAssert?: boolean): number {\n offset = offset >>> 0;\n byteLength = byteLength >>> 0;\n\n if (!noAssert) {\n Buffer._checkOffset(offset, byteLength, this.length);\n }\n\n let val = this[offset];\n let mul = 1;\n let i = 0;\n\n while (++i < byteLength && (mul *= 0x100)) {\n val += this[offset + i] * mul;\n }\n\n mul *= 0x80;\n\n if (val >= mul) {\n val -= Math.pow(2, 8 * byteLength);\n }\n\n return val;\n }\n\n /**\n * Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as a\n * big-endian, two's complement signed value supporting up to 48 bits of accuracy.\n *\n * @param offset Number of bytes to skip before starting to read.\n * @param byteLength Number of bytes to read, between 0 and 6.\n * @param noAssert\n */\n public readIntBE(offset: number, byteLength: number, noAssert?: boolean): number {\n offset = offset >>> 0;\n byteLength = byteLength >>> 0;\n\n if (!noAssert) {\n Buffer._checkOffset(offset, byteLength, this.length);\n }\n\n let i = byteLength;\n let mul = 1;\n let val = this[offset + --i];\n\n while (i > 0 && (mul *= 0x100)) {\n val += this[offset + --i] * mul;\n }\n\n mul *= 0x80;\n\n if (val >= mul) {\n val -= Math.pow(2, 8 * byteLength);\n }\n\n return val;\n }\n\n /**\n * Reads an unsigned 8-bit integer from `buf` at the specified `offset`.\n *\n * @param offset Number of bytes to skip before starting to read.\n * @param noAssert\n */\n public readUInt8(offset: number, noAssert?: boolean): number {\n offset = offset >>> 0;\n\n if (!noAssert) {\n Buffer._checkOffset(offset, 1, this.length);\n }\n\n return this[offset];\n }\n\n /**\n * Reads an unsigned, little-endian 16-bit integer from `buf` at the specified `offset`.\n *\n * @param offset Number of bytes to skip before starting to read.\n * @param noAssert\n */\n public readUInt16LE(offset: number, noAssert?: boolean): number {\n offset = offset >>> 0;\n\n if (!noAssert) {\n Buffer._checkOffset(offset, 2, this.length);\n }\n\n return this[offset] | (this[offset + 1] << 8);\n }\n\n /**\n * Reads an unsigned, big-endian 16-bit integer from `buf` at the specified `offset`.\n *\n * @param offset Number of bytes to skip before starting to read.\n * @param noAssert\n */\n public readUInt16BE(offset: number, noAssert?: boolean): number {\n offset = offset >>> 0;\n\n if (!noAssert) {\n Buffer._checkOffset(offset, 2, this.length);\n }\n\n return (this[offset] << 8) | this[offset + 1];\n }\n\n /**\n * Reads an unsigned, little-endian 32-bit integer from `buf` at the specified `offset`.\n *\n * @param offset Number of bytes to skip before starting to read.\n * @param noAssert\n */\n public readUInt32LE(offset: number, noAssert?: boolean): number {\n offset = offset >>> 0;\n\n if (!noAssert) {\n Buffer._checkOffset(offset, 4, this.length);\n }\n\n return (this[offset] | (this[offset + 1] << 8) | (this[offset + 2] << 16)) + this[offset + 3] * 0x1000000;\n }\n\n /**\n * Reads an unsigned, big-endian 32-bit integer from `buf` at the specified `offset`.\n *\n * @param offset Number of bytes to skip before starting to read.\n * @param noAssert\n */\n public readUInt32BE(offset: number, noAssert?: boolean): number {\n offset = offset >>> 0;\n\n if (!noAssert) {\n Buffer._checkOffset(offset, 4, this.length);\n }\n\n return this[offset] * 0x1000000 + ((this[offset + 1] << 16) | (this[offset + 2] << 8) | this[offset + 3]);\n }\n\n /**\n * Reads a signed 8-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer` are interpreted\n * as two's complement signed values.\n *\n * @param offset Number of bytes to skip before starting to read.\n * @param noAssert\n */\n public readInt8(offset: number, noAssert?: boolean): number {\n offset = offset >>> 0;\n\n if (!noAssert) {\n Buffer._checkOffset(offset, 1, this.length);\n }\n\n if (!(this[offset] & 0x80)) {\n return this[offset];\n }\n\n return (0xff - this[offset] + 1) * -1;\n }\n\n /**\n * Reads a signed, little-endian 16-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer`\n * are interpreted as two's complement signed values.\n *\n * @param offset Number of bytes to skip before starting to read.\n * @param noAssert\n */\n public readInt16LE(offset: number, noAssert?: boolean): number {\n offset = offset >>> 0;\n\n if (!noAssert) {\n Buffer._checkOffset(offset, 2, this.length);\n }\n\n const val = this[offset] | (this[offset + 1] << 8);\n return val & 0x8000 ? val | 0xffff0000 : val;\n }\n\n /**\n * Reads a signed, big-endian 16-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer`\n * are interpreted as two's complement signed values.\n *\n * @param offset Number of bytes to skip before starting to read.\n * @param noAssert\n */\n public readInt16BE(offset: number, noAssert?: boolean): number {\n offset = offset >>> 0;\n\n if (!noAssert) {\n Buffer._checkOffset(offset, 2, this.length);\n }\n\n const val = this[offset + 1] | (this[offset] << 8);\n return val & 0x8000 ? val | 0xffff0000 : val;\n }\n\n /**\n * Reads a signed, little-endian 32-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer`\n * are interpreted as two's complement signed values.\n *\n * @param offset Number of bytes to skip before starting to read.\n * @param noAssert\n */\n public readInt32LE(offset: number, noAssert?: boolean): number {\n offset = offset >>> 0;\n\n if (!noAssert) {\n Buffer._checkOffset(offset, 4, this.length);\n }\n\n return this[offset] | (this[offset + 1] << 8) | (this[offset + 2] << 16) | (this[offset + 3] << 24);\n }\n\n /**\n * Reads a signed, big-endian 32-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer`\n * are interpreted as two's complement signed values.\n *\n * @param offset Number of bytes to skip before starting to read.\n * @param noAssert\n */\n public readInt32BE(offset: number, noAssert?: boolean): number {\n offset = offset >>> 0;\n\n if (!noAssert) {\n Buffer._checkOffset(offset, 4, this.length);\n }\n\n return (this[offset] << 24) | (this[offset + 1] << 16) | (this[offset + 2] << 8) | this[offset + 3];\n }\n\n /**\n * Interprets `buf` as an array of unsigned 16-bit integers and swaps the byte order in-place.\n * Throws a `RangeError` if `buf.length` is not a multiple of 2.\n */\n public swap16(): Buffer {\n const len = this.length;\n\n if (len % 2 !== 0) {\n throw new RangeError('Buffer size must be a multiple of 16-bits');\n }\n\n for (let i = 0; i < len; i += 2) {\n this._swap(this, i, i + 1);\n }\n\n return this;\n }\n\n /**\n * Interprets `buf` as an array of unsigned 32-bit integers and swaps the byte order in-place.\n * Throws a `RangeError` if `buf.length` is not a multiple of 4.\n */\n public swap32(): Buffer {\n const len = this.length;\n\n if (len % 4 !== 0) {\n throw new RangeError('Buffer size must be a multiple of 32-bits');\n }\n\n for (let i = 0; i < len; i += 4) {\n this._swap(this, i, i + 3);\n this._swap(this, i + 1, i + 2);\n }\n\n return this;\n }\n\n /**\n * Interprets `buf` as an array of unsigned 64-bit integers and swaps the byte order in-place.\n * Throws a `RangeError` if `buf.length` is not a multiple of 8.\n */\n public swap64(): Buffer {\n const len = this.length;\n\n if (len % 8 !== 0) {\n throw new RangeError('Buffer size must be a multiple of 64-bits');\n }\n\n for (let i = 0; i < len; i += 8) {\n this._swap(this, i, i + 7);\n this._swap(this, i + 1, i + 6);\n this._swap(this, i + 2, i + 5);\n this._swap(this, i + 3, i + 4);\n }\n\n return this;\n }\n\n /**\n * Swaps two octets.\n *\n * @param b\n * @param n\n * @param m\n */\n private _swap(b: Buffer, n: number, m: number) {\n const i = b[n];\n b[n] = b[m];\n b[m] = i;\n }\n\n /**\n * Writes `value` to `buf` at the specified `offset`. The `value` must be a valid unsigned 8-bit integer.\n * Behavior is undefined when `value` is anything other than an unsigned 8-bit integer.\n *\n * @param value Number to write.\n * @param offset Number of bytes to skip before starting to write.\n * @param noAssert\n * @returns `offset` plus the number of bytes written.\n */\n public writeUInt8(value: number, offset: number, noAssert?: boolean): number {\n value = +value;\n offset = offset >>> 0;\n\n if (!noAssert) {\n Buffer._checkInt(this, value, offset, 1, 0xff, 0);\n }\n\n this[offset] = value & 0xff;\n return offset + 1;\n }\n\n /**\n * Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a valid unsigned 16-bit\n * integer. Behavior is undefined when `value` is anything other than an unsigned 16-bit integer.\n *\n * @param value Number to write.\n * @param offset Number of bytes to skip before starting to write.\n * @param noAssert\n * @returns `offset` plus the number of bytes written.\n */\n public writeUInt16LE(value: number | string, offset: number, noAssert?: boolean): number {\n value = +value;\n offset = offset >>> 0;\n\n if (!noAssert) {\n Buffer._checkInt(this, value, offset, 2, 0xffff, 0);\n }\n\n this[offset] = value & 0xff;\n this[offset + 1] = value >>> 8;\n return offset + 2;\n }\n\n /**\n * Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a valid unsigned 16-bit\n * integer. Behavior is undefined when `value` is anything other than an unsigned 16-bit integer.\n *\n * @param value Number to write.\n * @param offset Number of bytes to skip before starting to write.\n * @param noAssert\n * @returns `offset` plus the number of bytes written.\n */\n public writeUInt16BE(value: number, offset: number, noAssert?: boolean): number {\n value = +value;\n offset = offset >>> 0;\n\n if (!noAssert) {\n Buffer._checkInt(this, value, offset, 2, 0xffff, 0);\n }\n\n this[offset] = value >>> 8;\n this[offset + 1] = value & 0xff;\n\n return offset + 2;\n }\n\n /**\n * Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a valid unsigned 32-bit\n * integer. Behavior is undefined when `value` is anything other than an unsigned 32-bit integer.\n *\n * @param value Number to write.\n * @param offset Number of bytes to skip before starting to write.\n * @param noAssert\n * @returns `offset` plus the number of bytes written.\n */\n public writeUInt32LE(value: number, offset: number, noAssert?: boolean): number {\n value = +value;\n offset = offset >>> 0;\n\n if (!noAssert) {\n Buffer._checkInt(this, value, offset, 4, 0xffffffff, 0);\n }\n\n this[offset + 3] = value >>> 24;\n this[offset + 2] = value >>> 16;\n this[offset + 1] = value >>> 8;\n this[offset] = value & 0xff;\n return offset + 4;\n }\n\n /**\n * Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a valid unsigned 32-bit\n * integer. Behavior is undefined when `value` is anything other than an unsigned 32-bit integer.\n *\n * @param value Number to write.\n * @param offset Number of bytes to skip before starting to write.\n * @param noAssert\n * @returns `offset` plus the number of bytes written.\n */\n public writeUInt32BE(value: number, offset: number, noAssert?: boolean): number {\n value = +value;\n offset = offset >>> 0;\n\n if (!noAssert) {\n Buffer._checkInt(this, value, offset, 4, 0xffffffff, 0);\n }\n\n this[offset] = value >>> 24;\n this[offset + 1] = value >>> 16;\n this[offset + 2] = value >>> 8;\n this[offset + 3] = value & 0xff;\n\n return offset + 4;\n }\n\n /**\n * Writes `value` to `buf` at the specified `offset`. The `value` must be a valid signed 8-bit integer.\n * Behavior is undefined when `value` is anything other than a signed 8-bit integer.\n *\n * @param value Number to write.\n * @param offset Number of bytes to skip before starting to write.\n * @param noAssert\n * @returns `offset` plus the number of bytes written.\n */\n public writeInt8(value: number, offset: number, noAssert?: boolean): number {\n value = +value;\n offset = offset >>> 0;\n\n if (!noAssert) {\n Buffer._checkInt(this, value, offset, 1, 0x7f, -0x80);\n }\n\n if (value < 0) {\n value = 0xff + value + 1;\n }\n\n this[offset] = value & 0xff;\n return offset + 1;\n }\n\n /**\n * Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a valid signed 16-bit\n * integer. Behavior is undefined when `value` is anything other than a signed 16-bit integer.\n *\n * @param value Number to write.\n * @param offset Number of bytes to skip before starting to write.\n * @param noAssert\n * @returns `offset` plus the number of bytes written.\n */\n public writeInt16LE(value: number, offset: number, noAssert?: boolean): number {\n value = +value;\n offset = offset >>> 0;\n\n if (!noAssert) {\n Buffer._checkInt(this, value, offset, 2, 0x7fff, -0x8000);\n }\n\n this[offset] = value & 0xff;\n this[offset + 1] = value >>> 8;\n\n return offset + 2;\n }\n\n /**\n * Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a valid signed 16-bit\n * integer. Behavior is undefined when `value` is anything other than a signed 16-bit integer.\n *\n * @param value Number to write.\n * @param offset Number of bytes to skip before starting to write.\n * @param noAssert\n * @returns `offset` plus the number of bytes written.\n */\n public writeInt16BE(value: number, offset: number, noAssert?: boolean): number {\n value = +value;\n offset = offset >>> 0;\n\n if (!noAssert) {\n Buffer._checkInt(this, value, offset, 2, 0x7fff, -0x8000);\n }\n\n this[offset] = value >>> 8;\n this[offset + 1] = value & 0xff;\n\n return offset + 2;\n }\n\n /**\n * Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a valid signed 32-bit\n * integer. Behavior is undefined when `value` is anything other than a signed 32-bit integer.\n *\n * @param value Number to write.\n * @param offset Number of bytes to skip before starting to write.\n * @param noAssert\n * @returns `offset` plus the number of bytes written.\n */\n public writeInt32LE(value: number, offset: number, noAssert?: boolean): number {\n value = +value;\n offset = offset >>> 0;\n\n if (!noAssert) {\n Buffer._checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);\n }\n\n this[offset] = value & 0xff;\n this[offset + 1] = value >>> 8;\n this[offset + 2] = value >>> 16;\n this[offset + 3] = value >>> 24;\n\n return offset + 4;\n }\n\n /**\n * Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a valid signed 32-bit\n * integer. Behavior is undefined when `value` is anything other than a signed 32-bit integer.\n *\n * @param value Number to write.\n * @param offset Number of bytes to skip before starting to write.\n * @param noAssert\n * @returns `offset` plus the number of bytes written.\n */\n public writeInt32BE(value: number, offset: number, noAssert?: boolean): number {\n value = +value;\n offset = offset >>> 0;\n\n if (!noAssert) {\n Buffer._checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);\n }\n\n if (value < 0) {\n value = 0xffffffff + value + 1;\n }\n\n this[offset] = value >>> 24;\n this[offset + 1] = value >>> 16;\n this[offset + 2] = value >>> 8;\n this[offset + 3] = value & 0xff;\n\n return offset + 4;\n }\n\n /**\n * Fills `buf` with the specified `value`. If the `offset` and `end` are not given, the entire `buf` will be\n * filled. The `value` is coerced to a `uint32` value if it is not a string, `Buffer`, or integer. If the resulting\n * integer is greater than `255` (decimal), then `buf` will be filled with `value & 255`.\n *\n * If the final write of a `fill()` operation falls on a multi-byte character, then only the bytes of that\n * character that fit into `buf` are written.\n *\n * If `value` contains invalid characters, it is truncated; if no valid fill data remains, an exception is thrown.\n *\n * @param value\n * @param encoding\n */\n public fill(value: any, offset?: number, end?: number, encoding?: Encoding): this {\n if (typeof value === 'string') {\n if (typeof offset === 'string') {\n encoding = offset;\n offset = 0;\n end = this.length;\n } else if (typeof end === 'string') {\n encoding = end;\n end = this.length;\n }\n\n if (encoding !== undefined && typeof encoding !== 'string') {\n throw new TypeError('encoding must be a string');\n }\n\n if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {\n throw new TypeError('Unknown encoding: ' + encoding);\n }\n\n if (value.length === 1) {\n const code = value.charCodeAt(0);\n\n if (encoding === 'utf8' && code < 128) {\n // Fast path: If `val` fits into a single byte, use that numeric value.\n value = code;\n }\n }\n } else if (typeof value === 'number') {\n value = value & 255;\n } else if (typeof value === 'boolean') {\n value = Number(value);\n }\n\n // Apply defaults\n offset ??= 0;\n end ??= this.length;\n\n // Invalid ranges are not set to a default, so can range check early.\n if (offset < 0 || this.length < offset || this.length < end) {\n throw new RangeError('Out of range index');\n }\n\n if (end <= offset) {\n return this;\n }\n\n offset = offset >>> 0;\n end = end === undefined ? this.length : end >>> 0;\n value ||= 0;\n\n let i: number;\n\n if (typeof value === 'number') {\n for (i = offset; i < end; ++i) {\n this[i] = value;\n }\n } else {\n const bytes = Buffer.isBuffer(value) ? value : Buffer.from(value, encoding);\n const len = bytes.length;\n\n if (len === 0) {\n throw new TypeError('The value \"' + value + '\" is invalid for argument \"value\"');\n }\n\n for (i = 0; i < end - offset; ++i) {\n this[i + offset] = bytes[i % len];\n }\n }\n\n return this;\n }\n\n /*