import { Buffer as Buffer$1 } from 'node:buffer'; declare const customBufferSymbol: unique symbol; declare const customInspectSymbol: unique symbol; /** * The `Buffer` class is a cross platform alternative of [Node buffer](https://nodejs.org/api/buffer.html#class-buffer) base on `UInt8Array`. * @see See the [Buffer | Node.js Documentation](https://nodejs.org/api/buffer.html#class-buffer) for more information. * @property buffer - The underlying `ArrayBuffer` object based on which this `Buffer` object is created. */ declare class Buffer extends Uint8Array implements INodeBuffer { #private; /** * @hidden */ readonly [Symbol.toStringTag]: any; /** * Creates a zero-length `Buffer`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer() * console.log(buf.length) // Prints: 0 * })() * ``` */ constructor(); /** * Creates a new `Buffer` with `length` bytes. The contents are initialized to `0`. * @param length - The desired length of the new `Buffer`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(2) * console.log(buf.length) // Prints: 2 * })() * ``` */ constructor(length: number); /** * Creates a new `Buffer` copied from `arrayLike`. `TypedArray` will be treated as an `Array`. * @param arrayLike - An array of bytes in the range `0` – `255`. Array entries outside that range will be truncated to fit into it. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.of(21, 31) * console.log(buf1.toString('hex')) // Prints: 151f * * const buf2 = new Buffer(new Uint16Array([0x1234, 0x5678])) * console.log(buf2.toString('hex')) // Prints: 3478 * * const buf3 = Buffer.from('0102', 'hex') * const buf4 = new Buffer(buf3) * buf3[0] = 0x03 * console.log(buf3.toString('hex')) // Prints: 0302 * console.log(buf4.toString('hex')) // Prints: 0102 * })() * ``` */ constructor(arrayLike: ArrayLike | Iterable | ArrayBufferView); /** * Creates a view of the `arrayBuffer` without copying the underlying memory. For example, when passed a reference to the `.buffer` property of a `TypedArray` instance, the newly created `Buffer` will share the same allocated memory as the `TypedArray`'s underlying `ArrayBuffer`. * @param arrayBuffer - An `ArrayBuffer` or `SharedArrayBuffer`, for example the `.buffer` property of a `TypedArray`. * @param byteOffset - Index of first byte to expose. Default: `0`. * @param length - Number of bytes to expose. Default: `arrayBuffer.byteLength - byteOffset`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const uint16 = new Uint16Array([5000, 4000]) * const buf = Buffer.from(uint16.buffer) // Shares memory with `uint16`. * console.log(buf.toString('hex')) // Prints: 8813a00f * * uint16[1] = 6000 * console.log(buf.toString('hex')) // Prints: 88137017 * })() * ``` */ constructor(arrayBuffer: ArrayBufferLike | Buffer, byteOffset?: number, length?: number); /** * Allocates a new `Buffer` of `size` bytes. If `fill` is `undefined`, the `Buffer` will be zero-filled. * @param size - The desired length of the new `Buffer`. * @param fill - A value to pre-fill the new `Buffer` with. Default: `0`. * @group Static Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.alloc(5) * console.log(buf.toString('hex')) // Prints: 0000000000 * })() * ``` */ static alloc(size: number, fill?: Buffer | number | Uint8Array): Buffer; /** * Allocates a new `Buffer` of `size` bytes. If `fill` is `undefined`, the `Buffer` will be zero-filled. * @param size - The desired length of the new `Buffer`. * @param fill - A value to pre-fill the new `Buffer` with. Default: `0`. * @param encoding - The encoding of `fill`. Default: `'utf8'`. * @group Static Methods * @example * If `fill` is specified, the allocated `Buffer` will be initialized by calling `buf.fill(fill)`. * * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.alloc(5, 'a') * console.log(buf.toString('hex')) // Prints: 6161616161 * })() * ``` * @example * If both `fill` and `encoding` are specified, the allocated `Buffer` will be initialized by calling `buf.fill(fill, encoding)`. * * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64') * console.log(buf.toString('hex')) // Prints: 68656c6c6f20776f726c64 * })() * ``` */ static alloc(size: number, fill: string, encoding?: Encoding): Buffer; /** * Allocates a new `Buffer` of `size` bytes. The contents are initialized to `0`. This is equivalent to calling `new Buffer(size)`. * @remarks This method is different from Node.js's `Buffer.allocUnsafe()` method. * @param size - The desired length of the new Buffer. * @group Static Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.allocUnsafe(10) * console.log(buf.toString('hex')) // Prints: 00000000000000000000 * })() * ``` */ static allocUnsafe(size: number): Buffer; /** * Allocates a new `Buffer` of `size` bytes. The contents are initialized to `0`. This is equivalent to calling `new Buffer(size)`. * @remarks This method is different from Node.js's `Buffer.allocUnsafeSlow()` method. * @param size - The desired length of the new Buffer. * @group Static Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.allocUnsafeSlow(10) * console.log(buf.toString('hex')) // Prints: 00000000000000000000 * })() * ``` */ static allocUnsafeSlow(size: number): Buffer; /** * Returns `.byteLength` if `value` is a `Buffer`/`DataView`/`TypedArray`/`ArrayBuffer`/`SharedArrayBuffer`. * @param value - A value to calculate the length of bytes. * @returns The number of bytes contained within `value`. * @group Static Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const u8arr = new Uint8Array(5) * console.log(Buffer.byteLength(u8arr)) // Prints: 5 * })() * ``` */ static byteLength(value: ArrayBufferLike | ArrayBufferView): number; /** * Returns the byte length of a string when encoded using `encoding`. This is not the same as `String.prototype.length`, which does not account for the `encoding` that is used to convert the string into bytes. * * For `'base64'`, `'base64url'`, and `'hex'`, this method assumes `value` is valid. For strings that contain non-base64/hex-encoded data (e.g. whitespace), the return value might be greater than the length of a `Buffer` created from the string. * @param string - A value to calculate the length of bytes. * @param encoding - The encoding of `string`. Default: `'utf8'`. * @returns The number of bytes contained within `string`. * @group Static Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const str = '\u00bd + \u00bc = \u00be' * console.log(`${str}: ${str.length} characters, ${Buffer.byteLength(str, 'utf8')} bytes`) * // Prints: ½ + ¼ = ¾: 9 characters, 12 bytes * })() * ``` */ static byteLength(string: string, encoding?: Encoding): number; /** * Compares `buf1` to `buf2`, typically for the purpose of sorting arrays of `Buffer` instances. This is equivalent to calling {@link Buffer#compare}. * @param buf1 - * @param buf2 - * @returns Either `-1`, `0`, or `1`, depending on the result of the comparison. See {@link Buffer#compare} for details. * @group Static Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('1234') * const buf2 = Buffer.from('0123') * * console.log([buf1, buf2].sort(Buffer.compare).map(buf => buf.toString('hex'))) * // Prints: ['30313233', '31323334'] * // (This result is equal to: [buf2, buf1].) * * console.log([buf2, buf1].sort(Buffer.compare).map(buf => buf.toString('hex'))) * // Prints: ['30313233', '31323334'] * })() * ``` */ static compare(buf1: Buffer | Uint8Array, buf2: Buffer | Uint8Array): 0 | 1 | -1; /** * Returns a new `Buffer` which is the result of concatenating all the `Buffer` instances in the `list` together. * * If the `list` has no items, or if the `totalLength` is 0, then a new zero-length `Buffer` is returned. * * If `totalLength` is not provided, it is calculated from the `Buffer` instances in `list` by adding their lengths. * * If `totalLength` is provided, it is coerced to an unsigned integer. If the combined length of the `Buffer`s in `list` exceeds `totalLength`, the result is truncated to `totalLength`. * @param list - List of `Buffer` or `Uint8Array` instances to concatenate. * @param totalLength - Total length of the `Buffer` instances in `list` when concatenated. * @group Static Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.alloc(4) * const buf2 = Buffer.alloc(5) * const buf3 = Buffer.alloc(6) * const totalLength = buf1.length + buf2.length + buf3.length * console.log(totalLength) // Prints: 15 * * const bufA = Buffer.concat([buf1, buf2, buf3], totalLength) * console.log(bufA.toString('hex')) * // Prints: 000000000000000000000000000000 * console.log(bufA.length) // Prints: 15 * })() * ``` */ static concat(list: Buffer[], totalLength?: number): Buffer; /** * Copies the underlying memory of `view` into a new `Buffer`. * @param view - The `TypedArray` to copy. * @param offset - The starting offset within `view`. Default: `0`. * @param length - The number of elements from `view` to copy. Default: `view.length - offset`. * @group Static Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const u16 = new Uint16Array([0, 0xffff]) * const buf = Buffer.copyBytesFrom(u16, 1, 1) * u16[1] = 0 * console.log(buf.length) // Prints: 2 * console.log(buf.toString('hex')) // Prints: ffff * })() * ``` */ static copyBytesFrom(view: ArrayBufferView, offset?: number, length?: number): Buffer; /** * @returns `ture` if `buf1` and `buf2` have the same byte length and contents, or `false` otherwise. * @group Static Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * console.log(Buffer.equals(Buffer.of(1, 2), Buffer.from('0102', 'hex'))) // true * console.log(Buffer.equals(Buffer.from(Uint8Array.of(1, 2)), Buffer.from('0102', 'hex'))) // true * console.log(Buffer.equals(Uint8Array.of(1, 2), Buffer.from('0102', 'hex'))) // false * console.log(Buffer.equals(1, Uint8Array.of(1, 2))) // false * console.log(Buffer.equals('', new Buffer(2))) // false * })() * ``` */ static equals(buf1: Buffer, buf2: Buffer): boolean; /** * Allocates a new `Buffer` using an `array` of bytes in the range `0` – `255`. Array entries outside that range will be truncated to fit into it. * * If `array` is an `Array`-like object (that is, one with a `length` property of type `number`), it is treated as if it is an array, unless it is a `Buffer` or a `Uint8Array`. This means all other `TypedArray` variants get treated as an `Array`. To create a `Buffer` from the bytes backing a `TypedArray`, use {@link Buffer.copyBytesFrom}. * @param array - * @group Static Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]) * console.log(buf1.toString('hex')) // Prints: 627566666572 * * const u16 = new Uint16Array([0x0001, 0x0002]) * const buf2 = Buffer.from(u16) * console.log(buf2.toString('hex')) // Prints: 0102 * })() * ``` */ static from(array: OrValueOf | Iterable>): Buffer; /** * This creates a view of the `ArrayBuffer` without copying the underlying memory. For example, when passed a reference to the `.buffer` property of a `TypedArray` instance, the newly created `Buffer` will share the same allocated memory as the `TypedArray`'s underlying `ArrayBuffer`. * * The optional byteOffset and length arguments specify a memory range within the arrayBuffer that will be shared by the Buffer. * * It is important to remember that a backing `ArrayBuffer` can cover a range of memory that extends beyond the bounds of a `TypedArray` view. A new `Buffer` created using the `buffer` property of a `TypedArray` may extend beyond the range of the `TypedArray`: * @param arrayBuffer - An `ArrayBuffer`, `SharedArrayBuffer`, for example the `.buffer` property of a `TypedArray`. * @param byteOffset - Index of first byte to expose. Default: `0`. * @param length - Number of bytes to expose. Default: `arrayBuffer.byteLength - byteOffset`. * @group Static Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const arr = new Uint16Array(2) * arr[0] = 5000 * arr[1] = 4000 * const buf = Buffer.from(arr.buffer) // Shares memory with `arr` * console.log(buf.toString('hex')) // Prints: 8813a00f * * // Changing the original Uint16Array changes the Buffer also. * arr[1] = 6000 * console.log(buf.toString('hex')) // Prints: 88137017 * })() * ``` * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const ab = new ArrayBuffer(10) * const buf = Buffer.from(ab, 0, 2) * console.log(buf.length) // Prints: 2 * })() * ``` * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const arrA = Uint8Array.from([0x63, 0x64, 0x65, 0x66]) // 4 elements * const arrB = new Uint8Array(arrA.buffer, 1, 2) // 2 elements * console.log(arrA.buffer === arrB.buffer) // true * * const buf = Buffer.from(arrB.buffer) * console.log(buf.toString('hex')) // Prints: 63646566 * })() * ``` */ static from(arrayBuffer: OrValueOf, byteOffset?: number, length?: number): Buffer; /** * Copies the passed `buffer` data onto a new `Buffer` instance. * @param buffer - An existing `Buffer` or `Uint8Array` from which to copy data. * @group Static Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('buffer') * const buf2 = Buffer.from(buf1) * buf1[0] = 0x61 * console.log(buf1.toString()) // Prints: auffer * console.log(buf2.toString()) // Prints: buffer * })() * ``` */ static from(buffer: OrValueOf): Buffer; /** * Restore a `Buffer` in the format returned from {@link Buffer#toJSON}. * @param json - A JSON object returned from {@link Buffer#toJSON}. * @group Static Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('buffer') * const buf2 = Buffer.from(buf1.toJSON()) * console.log(buf1.equals(buf2)) // Prints: true * })() * ``` */ static from(json: { type: 'Buffer'; data: number[]; }): Buffer; /** * Creates a new `Buffer` containing `string`. The `encoding` parameter identifies the character encoding to be used when converting `string` into bytes. * @param object - A string to encode. * @param encoding - The encoding of string. Default: `'utf8'`. * @group Static Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('this is a tést') * const buf2 = Buffer.from('7468697320697320612074c3a97374', 'hex') * * console.log(buf1.toString()) // Prints: this is a tést * console.log(buf2.toString()) // Prints: this is a tést * console.log(buf1.toString('latin1')) // Prints: this is a tést * })() * ``` * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from(new String('this is a test')) * console.log(buf.toString('hex')) // Prints: 7468697320697320612074657374 * })() * ``` * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * class Foo { * [Symbol.toPrimitive]() { * return 'this is a test'; * } * } * * const buf = Buffer.from(new Foo(), 'utf8') * console.log(buf.toString('hex')) // Prints: 7468697320697320612074657374 * })() * ``` */ static from(object: OrValueOf | { [Symbol.toPrimitive]: (hint?: 'string') => string; }, encoding?: Encoding): Buffer; /** * Creates a new `Buffer` that encoded from the provided `latin1` using Latin-1 encoding. Latin-1 stands for [ISO-8859-1](https://en.wikipedia.org/wiki/ISO-8859-1). This character encoding only supports the Unicode characters from U+0000 to U+00FF. Each character is encoded using a single byte. Characters that do not fit into that range are truncated and will be mapped to characters in that range. * @param latin1 - A string to encode. * @group Static Methods */ static fromLatin1String(latin1: string): Buffer; /** * Creates a new `Buffer` that encoded from the provided `base64` using [Base64](https://en.wikipedia.org/wiki/Base64) encoding. When creating a `Buffer` from a string, this encoding will also correctly accept "URL and Filename Safe Alphabet" as specified in [RFC 4648, Section 5](https://tools.ietf.org/html/rfc4648#section-5). Whitespace characters such as spaces, tabs, and new lines contained within the base64-encoded string are ignored. * @param base64 - A string to encode. * @group Static Methods */ static fromBase64String(base64: string): Buffer; /** * Creates a new `Buffer` that encoded from the provided `base64` using base64url encoding. [base64url](https://tools.ietf.org/html/rfc4648#section-5) encoding as specified in [RFC 4648, Section 5](https://tools.ietf.org/html/rfc4648#section-5). When creating a `Buffer` from a string, this encoding will also correctly accept regular base64-encoded strings. * @param base64 - A string to encode. * @group Static Methods */ static fromBase64urlString(base64: string): Buffer; /** * Creates a new `Buffer` that encoded from the provided `hex` using hexadecimal encoding. Data truncation may occur when encode strings that do not exclusively consist of an even number of hexadecimal characters. * @param hex - A string to encode. * @group Static Methods */ static fromHexString(hex: string): Buffer; /** * Creates a new `Buffer` that encoded from the provided `string`. The `encoding` parameter identifies the character encoding to be used when converting `string` into bytes. * @param string - A string to encode. * @param encoding - The encoding of `string`. Default: `'utf8'`. * @group Static Methods */ static fromString(string: string, encoding: Encoding): Buffer; /** * Creates a new `Buffer` that encoded from the provided `ucs2` using UCS-2 encoding. UCS-2 used to refer to a variant of UTF-16 that did not support characters that had code points larger than U+FFFF. In Node.js, these code points are always supported. * @param ucs2 - A string to encode. * @group Static Methods */ static fromUcs2String(ucs2: string): Buffer; /** * Creates a new `Buffer` that encoded from the provided `utf8` using UTF-8 encoding. Multi-byte encoded Unicode characters. Many web pages and other document formats use [UTF-8](https://en.wikipedia.org/wiki/UTF-8). This is the default character encoding. * @param utf8 - A string to encode. * @see This method based on the [TextEncoder](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder/encode) API. * @group Static Methods */ static fromUtf8String(utf8: string): Buffer; /** * Creates a `Buffer` from `view` without copying the underlying memory. * @param view - The `ArrayBufferView` to create a `Buffer` from. * @param offset - The starting offset within `view`. Default: `0`. * @param length - The number of elements from `view` to copy. Default: `view.length - offset`. * @group Static Methods */ static fromView(view: ArrayBufferView, offset?: number, length?: number): Buffer; /** * A helper function which {@link Buffer.isBuffer} will invoke and determine whether `this` is a `Buffer` or not. * @returns `true` if `this` is a `Buffer`, `false` otherwise. * @hidden */ [customBufferSymbol](): boolean; /** * @returns `true` if `obj` is a `Buffer`, `false` otherwise. * @group Static Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * console.log(Buffer.isBuffer(Buffer.alloc(10))) // true * console.log(Buffer.isBuffer(Buffer.from('foo'))) // true * console.log(Buffer.isBuffer('a string')) // false * console.log(Buffer.isBuffer([])) // false * console.log(Buffer.isBuffer(new Uint8Array(1024))) // false * })() * ``` */ static isBuffer(obj: any): obj is Buffer; /** * @returns `true` if `encoding` is the name of a supported character encoding, or `false` otherwise. * @param encoding - A character encoding name to check. * @group Static Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * console.log(Buffer.isEncoding('utf8')) // true * console.log(Buffer.isEncoding('hex')) // true * console.log(Buffer.isEncoding('utf/8')) // false * console.log(Buffer.isEncoding('')) // false * })() * ``` */ static isEncoding(encoding: any): encoding is Encoding; /** * Parse a format string `format`. This is a internal method used by {@link Buffer.packCalcSize}, {@link Buffer.pack}, {@link Buffer.unpack} and {@link Buffer.iterUnpack}. * @param format - A format string. *

Byte Order, Size, and Alignment

* * The first character of the format string can be used to indicate the byte order, size and alignment of the packed data, according to the following table: * * | Character | Byte order | Size | Alignment | * | --------- | ---------- | ---- | --------- | * | `@` | native | standard | none | * | `=` | native | standard | none | * | `<` | little-endian | standard | none | * | `>` | big-endian | standard | none | * | `!` | big-endian | standard | none | * * If the first character is not one of these, `@` is assumed. * *

Format Characters

* * Format characters have the following meaning; the conversion between C and Python values should be obvious given their types. The ‘Size’ column refers to the size of the packed value in bytes. * * | Format | C Type | JavaScript Type | Size | Notes | * | ------ | ------ | --------------- | ---- | ----- | * | `x` | pad byte | no value | 1 | (1) | * | `c` | `char` | Buffer of length 1 | 1 | | * | `b` | `signed char` | number | 1 | | * | `B` | `unsigned char` | number | 1 | | * | `?` | `_Bool` | boolean | 1 | (2) | * | `h` | `short` | number | 2 | | * | `H` | `unsigned short` | number | 2 | | * | `i` | `int` | number | 4 | | * | `I` | `unsigned int` | number | 4 | | * | `l` | `long` | number | 4 | | * | `L` | `unsigned long` | number | 4 | | * | `q` | `long long` | BigInt of 64 bits | 8 | | * | `Q` | `unsigned long long` | BigInt of 64 bits | 8 | | * | `e` | (3) | number | 2 | (4) | * | `f` | `float` | number | 4 | (4) | * | `d` | `double` | number | 8 | (4) | * | `s` | `char[]` | Buffer | | (5) | * | `p` | `char[]` | Buffer | | (6) | * * Notes: * * 1. When packing, `x` inserts one NUL byte (`0x00`). * 2. The `?` conversion code corresponds to the _Bool type defined by C standards since C99. It is represented by one byte. * 3. The IEEE 754 binary16 "half precision" type was introduced in the 2008 revision of the [IEEE 754 standard](https://en.wikipedia.org/wiki/IEEE_754-2008_revision). It has a sign bit, a 5-bit exponent and 11-bit precision (with 10 bits explicitly stored), and can represent numbers between approximately `6.1e-05` and `6.5e+04` at full precision. This type is not widely supported by C compilers: on a typical machine, an unsigned short can be used for storage, but not for math operations. See the Wikipedia page on the [half-precision floating-point format](https://en.wikipedia.org/wiki/Half-precision_floating-point_format) for more information. * 4. For the `f`, `d` and `e` conversion codes, the packed representation uses the IEEE 754 binary32, binary64 or binary16 format (for `f`, `d` or `e` respectively), regardless of the floating-point format used by the platform. * 5. For the `s` format character, the count is interpreted as the length of the bytes, not a repeat count like for the other format characters; for example, `10s` means a single 10-byte Buffer mapping to or from a single Buffer, while `10c` means 10 separate one byte character elements (e.g., `cccccccccc`) mapping to or from ten different Buffer. (See Examples for a concrete demonstration of the difference.) If a count is not given, it defaults to `1`. For packing, the Buffer is truncated or padded with null bytes as appropriate to make it fit. For unpacking, the resulting Buffer always has exactly the specified number of bytes. As a special case, `0s` means a single, empty Buffer. * 6. The `p` format character encodes a "Pascal string", meaning a short variable-length string stored in a fixed number of bytes, given by the count. The first byte stored is the length of the string, or 255, whichever is smaller. The bytes of the string follow. If the string passed in to pack() is too long (longer than the count minus 1), only the leading `count-1` bytes of the string are stored. If the string is shorter than `count-1`, it is padded with null bytes so that exactly count bytes in all are used. Note that for `unpack()`, the `p` format character consumes count bytes, but that the string returned can never contain more than 255 bytes. * * A format character may be preceded by an integral repeat count. For example, the format string `4h` means exactly the same as `hhhh`. * * For the `?` format character, the return value is either `true` or `false`. When packing, the truth value of the argument object is used. Either `0` or `1` in the bool representation will be packed, and any non-zero value will be `true` when unpacking. * @remarks Unlike Python struct, this method does not support native size and alignment (that wouldn't make much sense in a javascript). Instead, specify byte order and emit pad bytes explicitly. * @group Static Methods */ static packParseFormat(format: string): PackFormat; /** * Return the required size corresponding to the format string `formatOrItems`. * @param formatOrItems - A format string or parsed items return by items of {@link Buffer.packParseFormat}. * @remarks Unlike Python struct, this method does not support native size and alignment (that wouldn't make much sense in a javascript). Instead, specify byte order and emit pad bytes explicitly. * @group Static Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * console.log(Buffer.packCalcSize('>bhl')) // Prints: 7 * console.log(Buffer.packCalcSize('>ci')) // Prints: 5 * console.log(Buffer.packCalcSize('>ic')) // Prints: 5 * console.log(Buffer.packCalcSize('>lhl')) // Prints: 10 * console.log(Buffer.packCalcSize('>llh')) // Prints: 10 * console.log(Buffer.packCalcSize('>llh0l')) // Prints: 10 * console.log(Buffer.packCalcSize('h', 1023).toString('hex')) // Prints: 03ff * console.log(Buffer.pack('bhl', 1, 2, 3).toString('hex')) // Prints: 01000200000003 * })() * ``` */ static pack(format: string, ...vals: any[]): Buffer; /** * Pack `vals` into `buf` according to the format string `format`. The arguments must match the `vals` required by the `format` exactly. The `buf`’s size in bytes must larger then the size required by the `format`, as reflected by {@link Buffer.packCalcSize}. * @param buf - A `Buffer` to pack into. * @param format - A format string. Please refer to {@link Buffer.packParseFormat} for more information. * @param vals - Values to pack. * @remarks Unlike Python struct, this method does not support native size and alignment (that wouldn't make much sense in a javascript). Instead, specify byte order and emit pad bytes explicitly. * @group Static Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.alloc(3) * Buffer.pack(buf1, '>h', 0x0102) * console.log(buf1.toString('hex')) // Prints: 010200 * * const buf2 = Buffer.alloc(3) * Buffer.pack(buf2.subarray(1), '>h', 0x0102) // struct.pack_into * console.log(buf2.toString('hex')) // Prints: 000102 * })() * ``` */ static pack(buf: Buffer, format: string, ...vals: any[]): Buffer; /** * Unpack from the `buf` (presumably packed by `pack(format, ...)`) according to the format string `format`. The result is a tuple even if it contains exactly one item. The `buf`’s size in bytes must larger then the size required by the `format`, as reflected by {@link Buffer.packCalcSize}. * @param buf - A `Buffer` to unpack from. * @param format - A format string. Please refer to {@link Buffer.packParseFormat} for more information. * @remarks Unlike Python struct, this method does not support native size and alignment (that wouldn't make much sense in a javascript). Instead, specify byte order and emit pad bytes explicitly. * @group Static Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('01fe01fe', 'hex') * console.log(Buffer.unpack(buf1, '!BBbb')) // Prints: [1, 254, 1, -2] * })() * ``` */ static unpack(buf: Buffer, format: string): T; /** * Iteratively unpack from the `buf` according to the format string `format`. This method returns an iterator which will read equally sized chunks from the `buf` until remaining contents smaller then the size required by the `format`, as reflected by {@link Buffer.packCalcSize}. * @param buf - A `Buffer` to unpack from. * @param format - A format string. Please refer to {@link Buffer.packParseFormat} for more information. * @remarks Unlike Python struct, this method does not support native size and alignment (that wouldn't make much sense in a javascript). Instead, specify byte order and emit pad bytes explicitly. * @group Static Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('01fe01fe', 'hex') * console.log([...Buffer.iterUnpack(buf1, '!BB')]) // Prints: [[1, 254], [1, 254]] * })() * ``` */ static iterUnpack(buf: Buffer, format: string): Generator; /** * Compares `buf` with `target` and returns a number indicating whether `buf` comes before, after, or is the same as `target` in sort order. Comparison is based on the actual sequence of bytes in each `Buffer`. * * The optional `targetStart`, `targetEnd`, `sourceStart`, and `sourceEnd` arguments can be used to limit the comparison to specific ranges within `target` and `buf` respectively. * @param target - A `Buffer` or `Uint8Array` with which to compare `buf`. * @param targetStart - The offset within `target` at which to begin comparison. Default: `0`. * @param targetEnd - The offset within `target` at which to end comparison (not inclusive). Default: `target.length`. * @param sourceStart - The offset within `buf` at which to begin comparison. Default: `0`. * @param sourceEnd - The offset within buf at which to end comparison (not inclusive). Default: `this.length`. * @returns * - `0` is returned if `target` is the same as `buf` * - `1` is returned if `target` should come before `buf` when sorted. * - `-1` is returned if `target` should come after `buf` when sorted. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('ABC') * const buf2 = Buffer.from('BCD') * const buf3 = Buffer.from('ABCD') * * console.log(buf1.compare(buf1)) // Prints: 0 * console.log(buf1.compare(buf2)) // Prints: -1 * console.log(buf1.compare(buf3)) // Prints: -1 * console.log(buf2.compare(buf1)) // Prints: 1 * console.log(buf2.compare(buf3)) // Prints: 1 * * console.log([buf1, buf2, buf3].sort(Buffer.compare).map(buf => buf.toString())) * // Prints: ['ABC', 'ABCD', 'BCD'] * })() * ``` * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9]) * const buf2 = Buffer.from([5, 6, 7, 8, 9, 1, 2, 3, 4]) * * console.log(buf1.compare(buf2, 5, 9, 0, 4)) // Prints: 0 * console.log(buf1.compare(buf2, 0, 6, 4)) // Prints: -1 * console.log(buf1.compare(buf2, 5, 6, 5)) // Prints: 1 * })() * ``` */ compare(target: any, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): 0 | 1 | -1; /** * Copies data from a region of `buf` to a region in `target`, even if the `target` memory region overlaps with `buf`. * * `TypedArray.prototype.set()` performs the same operation, and is available for all TypedArrays, including Node.js `Buffer`s, although it takes different function arguments. * @param target - A `Buffer` or `Uint8Array` to copy into. * @param targetStart - The offset within `target` at which to begin writing. Default: `0`. * @param sourceStart - The offset within `buf` from which to begin copying. Default: `0`. * @param sourceEnd - The offset within `buf` at which to stop copying (not inclusive). Default: `this.length`. * @returns The number of bytes copied. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.allocUnsafe(26) * const buf2 = Buffer.allocUnsafe(26).fill('!') * * // 97 is the decimal ASCII value for 'a'. * for (let i = 0; i < 26; i++) buf1[i] = i + 97 * * // Copy `buf1` bytes 16 through 19 into `buf2` starting at byte 8 of `buf2`. * buf1.copy(buf2, 8, 16, 20) * // This is equivalent to: * // buf2.set(buf1.subarray(16, 20), 8) * * console.log(buf2.toString('ascii', 0, 25)) * // Prints: !!!!!!!!qrst!!!!!!!!!!!!! * })() * ``` * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * // Create a `Buffer` and copy data from one region to an overlapping region within the same `Buffer`. * const buf = Buffer.allocUnsafe(26) * * // 97 is the decimal ASCII value for 'a'. * for (let i = 0; i < 26; i++) buf[i] = i + 97 * buf.copy(buf, 0, 4, 10) * * console.log(buf.toString()) * // Prints: efghijghijklmnopqrstuvwxyz * })() * ``` */ copy(target: ArrayBufferView, targetStart?: number, sourceStart?: number, sourceEnd?: number): number; /** * The method shallow copies part of this `Buffer` to another location in the same `Buffer` and returns this `Buffer` without modifying its length. * @group Methods * @param target - Zero-based index at which to copy the sequence to. This corresponds to where the element at start will be copied to, and all elements between start and end are copied to succeeding indices. * @param start - Zero-based index at which to start copying elements from. * @param end - Zero-based index at which to end copying elements from. This method copies up to but not including end. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(8) * buf.set([1, 2, 3]) * console.log(buf.toString('hex')) // Prints: 0102030000000000 * buf.copyWithin(3, 0, 3) * console.log(buf.toString('hex')) // Prints: 0102030102030000 * })() * ``` */ copyWithin: (target: number, start: number, end?: number) => this; /** * @param otherBuffer - A Buffer or Uint8Array with which to compare buf. * @returns `true` if both `buf` and `otherBuffer` have exactly the same bytes, `false` otherwise. Equivalent to `buf.compare(otherBuffer) === 0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('ABC') * const buf2 = Buffer.from('414243', 'hex') * const buf3 = Buffer.from('ABCD') * * console.log(buf1.equals(buf2)) // Prints: true * console.log(buf1.equals(buf3)) // Prints: false * })() * ``` */ equals(otherBuffer: this | Uint8Array): boolean; /** * Fill the entire `buf` with the specified `value`. * @param value - The value with which to fill buf. Empty string is coerced to `0`. * @param encoding - The encoding for `value`. Default: `'utf8'`. */ fill(value: string, encoding?: Encoding): this; /** * Fill the `buf` with the specified `value` start from `offset`. * @param value - The value with which to fill buf. Empty string is coerced to `0`. * @param offset - Number of bytes to skip before starting to fill `buf`. Default: `0`. * @param encoding - The encoding for `value`. Default: `'utf8'`. */ fill(value: string, offset: number, encoding?: Encoding): this; /** * Fill the `buf` with the specified `value` start from `offset` and stop before `end`. * @param value - The value with which to fill buf. Empty string is coerced to `0`. * @param offset - Number of bytes to skip before starting to fill `buf`. Default: `0`. * @param end - Where to stop filling `buf` (not inclusive). Default: `buf.length`. * @param encoding - The encoding for `value`. Default: `'utf8'`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * // Fill a `Buffer` with the ASCII character 'h'. * const b = Buffer.allocUnsafe(10).fill('h') * console.log(b.toString()) // Prints: hhhhhhhhhh * * // Fill a buffer with empty string * const c = Buffer.allocUnsafe(5).fill('') * console.log(c.toString('hex')) // Prints: 0000000000 * })() * ``` * @example * If the final write of a `fill()` operation falls on a multi-byte character, then only the bytes of that character that fit into `buf` are written: * * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * // Fill a `Buffer` with character that takes up two bytes in UTF-8. * const b = Buffer.allocUnsafe(5).fill('\u0222') * console.log(b.toString('hex')) // Prints: c8a2c8a2c8 * })() * ``` * @example * If `value` contains invalid characters, it is truncated; if no valid fill data remains, an exception is thrown: * * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.allocUnsafe(5) * * console.log(buf.fill('a').toString('hex')) // Prints: 6161616161 * console.log(buf.fill('aazz', 'hex').toString('hex')) // Prints: aaaaaaaaaa * console.log(buf.fill('zz', 'hex').toString('hex')) // Throws an exception. * })() * ``` */ fill(value: string, offset: number, end: number, encoding?: Encoding): this; /** * Fill `buf` with the specified `value`. If the `offset` and `end` are not given, the entire `buf` will be filled. * * @param value - The value with which to fill `buf`. Empty value (Uint8Array, Buffer) is coerced to `0`. `value` is coerced to a `uint32` value if it is not a string, `Buffer`, or integer. If the resulting integer is greater than `255` (decimal), `buf` will be filled with `value & 255`. * @param offset - Number of bytes to skip before starting to fill `buf`. Default: `0`. * @param end - Where to stop filling `buf` (not inclusive). Default: `buf.length`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * // Fill a `Buffer` with a Buffer * const buf1 = Buffer.allocUnsafe(10).fill(Buffer.of(65)) * console.log(buf1.toString()) // Prints: AAAAAAAAAA * * // Fill a `Buffer` with an Uint8Array * const buf2 = Buffer.allocUnsafe(10).fill(Uint8Array.of(65)) * console.log(buf2.toString()) // Prints: AAAAAAAAAA * * // Fill a `Buffer` with number * const buf3 = Buffer.allocUnsafe(10).fill(65) * console.log(buf3.toString()) // Prints: AAAAAAAAAA * })() * ``` */ fill(value: this | Uint8Array | number, offset?: number, end?: number): this; /** * Equivalent to `buf.indexOf() !== -1`. * @param value - What to search for. * @param encoding - The encoding of `value`. Default: `'utf8'`. * @returns `true` if `value` was found in `buf`, `false` otherwise. */ includes(value: string, encoding?: Encoding): boolean; /** * Equivalent to `buf.indexOf() !== -1`. * @param value - What to search for. * @param byteOffset - Where to begin searching in `buf`. If negative, then offset is calculated from the end of `buf`. Default: `0`. * @param encoding - The encoding of `value`. Default: `'utf8'`. * @returns `true` if `value` was found in `buf`, `false` otherwise. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from('this is a buffer') * console.log(buf.includes('this')) // Prints: true * console.log(buf.includes('is')) // Prints: true * console.log(buf.includes('this', 4)) // Prints: false * })() * ``` */ includes(value: string, byteOffset: number, encoding?: Encoding): boolean; /** * Equivalent to `buf.indexOf() !== -1`. * @param value - What to search for. * @param byteOffset - Where to begin searching in `buf`. If negative, then offset is calculated from the end of `buf`. Default: `0`. * @returns `true` if `value` was found in `buf`, `false` otherwise. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from('this is a buffer') * console.log(buf.includes(Buffer.from('a buffer'))) // Prints: true * console.log(buf.includes(97)) // Prints: true (97 is the decimal ASCII value for 'a') * console.log(buf.includes(Uint8Array.of(97))) // Prints: true (97 is the decimal ASCII value for 'a') * console.log(buf.includes(Buffer.from('a buffer example'))) // Prints: false * console.log(buf.includes(Buffer.from('a buffer example').slice(0, 8))) // Prints: true * })() * ``` */ includes(value: this | Uint8Array | number, byteOffset?: number): boolean; /** * @param value - What to search for. * - If `value` is a string, `value` is interpreted according to the character encoding in `encoding`. * - If `value` is a `Buffer` or `Uint8Array`, `value` will be used in its entirety. To compare a partial Buffer, use {@link Buffer#subarray}. * - If `value` is a number, it will be coerced to a valid byte value, an integer between `0` and `255`. * - If `value` is an empty string or empty Buffer and `byteOffset` is less than `buf.length`, `byteOffset` will be returned. * - If `value` is empty and `byteOffset` is at least `buf.length`, `buf.length` will be returned. * @param encoding - The encoding of `value`. Default: `'utf8'`. * @returns * - The index of the first occurrence of `value` in `buf` * - `-1` if `buf` does not contain value. * @throws * - If `value` is not a string, number, or `Buffer`, this method will throw a `TypeError`. */ indexOf(value: string, encoding?: Encoding): number; /** * @param value - What to search for. * - If `value` is a string, `value` is interpreted according to the character encoding in `encoding`. * - If `value` is a `Buffer` or `Uint8Array`, `value` will be used in its entirety. To compare a partial Buffer, use {@link Buffer#subarray}. * - If `value` is a number, it will be coerced to a valid byte value, an integer between `0` and `255`. * - If `value` is an empty string or empty Buffer and `byteOffset` is less than `buf.length`, `byteOffset` will be returned. * - If `value` is empty and `byteOffset` is at least `buf.length`, `buf.length` will be returned. * @param byteOffset - Where to begin searching in `buf`. Default: `0`. * - If negative, then offset is calculated from the end of `buf`. * - If not a integer, it will be coerced to integer by `_.toSafeInteger`. * @param encoding - The encoding of `value`. Default: `'utf8'`. * @returns * - The index of the first occurrence of `value` in `buf` * - `-1` if `buf` does not contain value. * @throws * - If `value` is not a string, number, or `Buffer`, this method will throw a `TypeError`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from('this is a buffer') * console.log(buf.indexOf('this')) // Prints: 0 * console.log(buf.indexOf('is')) // Prints: 2 * * const utf16Buffer = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'utf16le') * console.log(utf16Buffer.indexOf('\u03a3', 0, 'utf16le')) // Prints: 4 * console.log(utf16Buffer.indexOf('\u03a3', -4, 'utf16le')) // Prints: 6 * })() * ``` * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const b = Buffer.from('abcdef') * * // Passing a byteOffset that coerces to 0. * // Prints: 1, searching the whole buffer. * console.log(b.indexOf('b', undefined)) * console.log(b.indexOf('b', {})) * console.log(b.indexOf('b', null)) * console.log(b.indexOf('b', [])) * })() * ``` */ indexOf(value: string, byteOffset: number, encoding?: Encoding): number; /** * @param value - What to search for. * - If `value` is a string, `value` is interpreted according to the character encoding in `encoding`. * - If `value` is a `Buffer` or `Uint8Array`, `value` will be used in its entirety. To compare a partial Buffer, use {@link Buffer#subarray}. * - If `value` is a number, it will be coerced to a valid byte value, an integer between `0` and `255`. * - If `value` is an empty string or empty Buffer and `byteOffset` is less than `buf.length`, `byteOffset` will be returned. * - If `value` is empty and `byteOffset` is at least `buf.length`, `buf.length` will be returned. * @param byteOffset - Where to begin searching in `buf`. Default: `0`. * - If negative, then offset is calculated from the end of `buf`. * - If not a integer, it will be coerced to integer by `_.toSafeInteger`. * @returns * - The index of the first occurrence of `value` in `buf` * - `-1` if `buf` does not contain value. * @throws * - If `value` is not a string, number, or `Buffer`, this method will throw a `TypeError`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from('this is a buffer') * console.log(buf.indexOf(Buffer.from('a buffer'))) // Prints: 8 * console.log(buf.indexOf(97)) // Prints: 8 (97 is the decimal ASCII value for 'a') * console.log(buf.indexOf(Buffer.from('a buffer example'))) // Prints: -1 * console.log(buf.indexOf(Buffer.from('a buffer example').slice(0, 8))) // Prints: 8 * })() * ``` * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const b = Buffer.from('abcdef') * * // Passing a value that's a number, but not a valid byte. * // Prints: 2, equivalent to searching for 99 or 'c'. * console.log(b.indexOf(99.9)) * console.log(b.indexOf(256 + 99)) * })() * ``` */ indexOf(value: this | Uint8Array | number, byteOffset?: number): number; /** * Identical to {@link Buffer#indexOf}, except the last occurrence of `value` is found rather than the first occurrence. * @param value - What to search for. * - If `value` is a string, `value` is interpreted according to the character encoding in `encoding`. * - If `value` is a `Buffer` or `Uint8Array`, `value` will be used in its entirety. To compare a partial Buffer, use {@link Buffer#subarray}. * - If `value` is a number, it will be coerced to a valid byte value, an integer between `0` and `255`. * - If `value` is an empty string or empty `Buffer`, `byteOffset` will be returned. * @param encoding - The encoding of `value`. Default: `'utf8'`. * @returns * - The index of the last occurrence of `value` in `buf` * - `-1` if `buf` does not contain `value`. * @throws * - If `value` is not a string, number, or `Buffer`, this method will throw a `TypeError`. */ lastIndexOf(value: string, encoding?: Encoding): number; /** * Identical to {@link Buffer#indexOf}, except the last occurrence of `value` is found rather than the first occurrence. * @param value - What to search for. * - If `value` is a string, `value` is interpreted according to the character encoding in `encoding`. * - If `value` is a `Buffer` or `Uint8Array`, `value` will be used in its entirety. To compare a partial Buffer, use {@link Buffer#subarray}. * - If `value` is a number, it will be coerced to a valid byte value, an integer between `0` and `255`. * - If `value` is an empty string or empty `Buffer`, `byteOffset` will be returned. * @param byteOffset - Where to begin searching in `buf`. Default: `buf.length - 1`. * - If negative, then offset is calculated from the end of `buf`. * - If not a integer, it will be coerced to integer by `_.toSafeInteger`. * @param encoding - The encoding of `value`. Default: `'utf8'`. * @returns * - The index of the last occurrence of `value` in `buf` * - `-1` if `buf` does not contain `value`. * @throws * - If `value` is not a string, number, or `Buffer`, this method will throw a `TypeError`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from('this buffer is a buffer') * * console.log(buf.lastIndexOf('this')) // Prints: 0 * console.log(buf.lastIndexOf('buffer')) // Prints: 17 * console.log(buf.lastIndexOf('buffer', 5)) // Prints: 5 * console.log(buf.lastIndexOf('buffer', 4)) // Prints: -1 * * const utf16Buffer = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'utf16le') * console.log(utf16Buffer.lastIndexOf('\u03a3', undefined, 'utf16le')) // Prints: 6 * console.log(utf16Buffer.lastIndexOf('\u03a3', -5, 'utf16le')) // Prints: 4 * })() * ``` * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const b = Buffer.from('abcdef') * * // Passing a byteOffset that coerces to NaN. * // Prints: 1, searching the whole buffer. * console.log(b.lastIndexOf('b', undefined)) * console.log(b.lastIndexOf('b', {})) * * // Passing a byteOffset that coerces to 0. * // Prints: -1, equivalent to passing 0. * console.log(b.lastIndexOf('b', null)) * console.log(b.lastIndexOf('b', [])) * })() * ``` */ lastIndexOf(value: string, byteOffset: number, encoding?: Encoding): number; /** * Identical to {@link Buffer#indexOf}, except the last occurrence of `value` is found rather than the first occurrence. * @param value - What to search for. * - If `value` is a number, it will be coerced to a valid byte value, an integer between `0` and `255`. * - If `value` is an empty string or empty `Buffer`, `byteOffset` will be returned. * @param byteOffset - Where to begin searching in `buf`. Default: `buf.length - 1`. * - If negative, then offset is calculated from the end of `buf`. * - If not a integer, it will be coerced to integer by `_.toSafeInteger`. * @returns * - The index of the last occurrence of `value` in `buf` * - `-1` if `buf` does not contain `value`. * @throws * - If `value` is not a string, number, or `Buffer`, this method will throw a `TypeError`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from('this buffer is a buffer') * * console.log(buf.lastIndexOf(Buffer.from('buffer'))) // Prints: 17 * console.log(buf.lastIndexOf(97)) // Prints: 15 (97 is the decimal ASCII value for 'a') * console.log(buf.lastIndexOf(Buffer.from('yolo'))) // Prints: -1 * })() * ``` * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const b = Buffer.from('abcdef') * * // Passing a value that's a number, but not a valid byte. * // Prints: 2, equivalent to searching for 99 or 'c'. * console.log(b.lastIndexOf(99.9)) * console.log(b.lastIndexOf(256 + 99)) * })() * ``` */ lastIndexOf(value: this | Uint8Array | number, byteOffset?: number): number; /** * Reads a signed, big-endian 64-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer` are interpreted as two's complement signed values. * @param offset - Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from('00000000ffffffff', 'hex') * console.log(buf.readBigInt64BE(0)) // Prints: 4294967295n * })() * ``` */ readBigInt64BE(offset?: number): bigint; /** * Reads a signed, little-endian 64-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer` are interpreted as two's complement signed values. * @param offset - Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from('00000000ffffffff', 'hex') * console.log(buf.readBigInt64LE(0)) // Prints: -4294967296n * })() * ``` */ readBigInt64LE(offset?: number): bigint; /** * Reads an unsigned, big-endian 64-bit integer from buf at the specified offset. * @param offset - Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from('00000000ffffffff', 'hex') * console.log(buf.readBigUInt64BE(0)) // Prints: 4294967295n * })() * ``` */ readBigUInt64BE(offset?: number): bigint; /** * Alias of {@link Buffer.readBigUInt64BE}. * @group Alias Methods */ get readBigUint64BE(): this['readBigUInt64BE']; /** * Reads an unsigned, little-endian 64-bit integer from `buf` at the specified `offset`. * @param offset - Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from('00000000ffffffff', 'hex') * console.log(buf.readBigUInt64LE(0)) // Prints: 18446744069414584320n * })() * ``` */ readBigUInt64LE(offset?: number): bigint; /** * Alias of {@link Buffer.readBigUInt64LE}. * @group Alias Methods */ get readBigUint64LE(): this['readBigUInt64LE']; /** * Reads a 64-bit, big-endian double from `buf` at the specified `offset`. * @param offset - Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 8`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from('0102030405060708', 'hex') * console.log(buf.readDoubleBE(0)) // Prints: 8.20788039913184e-304 * })() * ``` */ readDoubleBE(offset?: number): number; /** * Reads a 64-bit, little-endian double from `buf` at the specified `offset`. * @param offset - Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 8`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from('0102030405060708', 'hex') * console.log(buf.readDoubleLE(0)) // Prints: 5.447603722011605e-270 * })() * ``` */ readDoubleLE(offset?: number): number; /** * Reads a 32-bit, big-endian float from `buf` at the specified `offset`. * @param offset - Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from('01020304', 'hex') * console.log(buf.readFloatBE(0)) // Prints: 2.387939260590663e-38 * })() * ``` */ readFloatBE(offset?: number): number; /** * Reads a 32-bit, little-endian float from `buf` at the specified `offset`. * @param offset - Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from('01020304', 'hex') * console.log(buf.readFloatLE(0)) // Prints: 1.539989614439558e-36 * })() * ``` */ readFloatLE(offset?: number): number; /** * Reads a signed 8-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer` are interpreted as two's complement signed values. * @param offset - Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 1`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from([-1, 5]) * console.log(buf.readInt8(0)) // Prints: -1 * console.log(buf.readInt8(1)) // Prints: 5 * })() * ``` */ readInt8(offset?: number): number; /** * Reads a signed, big-endian 16-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer` are interpreted as two's complement signed values. * @param offset - Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from([0, 5]) * console.log(buf.readInt16BE(0)) // Prints: 5 * })() * ``` */ readInt16BE(offset?: number): number; /** * Reads a signed, little-endian 16-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer` are interpreted as two's complement signed values. * @param offset - Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from([0, 5]) * console.log(buf.readInt16LE(0)) // Prints: 1280 * })() * ``` */ readInt16LE(offset?: number): number; /** * Reads a signed, big-endian 32-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer` are interpreted as two's complement signed values. * @param offset - Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from([0, 0, 0, 5]) * console.log(buf.readInt32BE(0)) // Prints: 5 * })() * ``` */ readInt32BE(offset?: number): number; /** * Reads a signed, little-endian 32-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer` are interpreted as two's complement signed values. * @param offset - Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from([0, 0, 0, 5]) * console.log(buf.readInt32LE(0)) // Prints: 83886080 * })() * ``` */ readInt32LE(offset?: number): number; /** * Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as a big-endian, two's complement signed value supporting up to 48 bits of accuracy. * @param offset - Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`. * @param byteLength - Number of bytes to read. Must satisfy `1 <= byteLength <= 6`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]) * console.log(buf.readIntBE(0, 6).toString(16)) // Prints: 1234567890ab * })() * ``` */ readIntBE(offset?: number, byteLength?: number): number; /** * Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as a little-endian, two's complement signed value supporting up to 48 bits of accuracy. * @param offset - Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`. * @param byteLength - Number of bytes to read. Must satisfy `1 <= byteLength <= 6`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]) * console.log(buf.readIntLE(0, 6).toString(16)) // Prints: -546f87a9cbee * })() * ``` */ readIntLE(offset?: number, byteLength?: number): number; /** * Reads an unsigned 8-bit integer from `buf` at the specified `offset`. * @param offset - Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 1`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from([1, -2]) * console.log(buf.readUInt8(0)) // Prints: 1 * console.log(buf.readUInt8(1)) // Prints: 254 * })() * ``` */ readUInt8(offset?: number): number; /** * Alias of {@link Buffer.readUInt8}. * @group Alias Methods */ get readUint8(): this['readUInt8']; /** * Reads an unsigned, big-endian 16-bit integer from `buf` at the specified `offset`. * @param offset - Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from([0x12, 0x34, 0x56]) * console.log(buf.readUInt16BE(0).toString(16)) // Prints: 1234 * console.log(buf.readUInt16BE(1).toString(16)) // Prints: 3456 * })() * ``` */ readUInt16BE(offset?: number): number; /** * Alias of {@link Buffer.readUInt16BE}. * @group Alias Methods */ get readUint16BE(): this['readUInt16BE']; /** * Reads an unsigned, little-endian 16-bit integer from `buf` at the specified `offset`. * @param offset - Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from([0x12, 0x34, 0x56]) * console.log(buf.readUInt16LE(0).toString(16)) // Prints: 3412 * console.log(buf.readUInt16LE(1).toString(16)) // Prints: 5634 * })() * ``` */ readUInt16LE(offset?: number): number; /** * Alias of {@link Buffer.readUInt16LE}. * @group Alias Methods */ get readUint16LE(): this['readUInt16LE']; /** * Reads an unsigned, big-endian 32-bit integer from `buf` at the specified `offset`. * @param offset - Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]) * console.log(buf.readUInt32BE(0).toString(16)) // Prints: 12345678 * })() * ``` */ readUInt32BE(offset?: number): number; /** * Alias of {@link Buffer.readUInt32BE}. * @group Alias Methods */ get readUint32BE(): this['readUInt32BE']; /** * Reads an unsigned, little-endian 32-bit integer from `buf` at the specified `offset`. * @param offset - Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]) * console.log(buf.readUInt32LE(0).toString(16)) // Prints: 78563412 * })() * ``` */ readUInt32LE(offset?: number): number; /** * Alias of {@link Buffer.readUInt32LE}. * @group Alias Methods */ get readUint32LE(): this['readUInt32LE']; /** * Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as an unsigned big-endian integer supporting up to 48 bits of accuracy. * @param offset - Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`. * @param byteLength - Number of bytes to read. Must satisfy `0 < byteLength <= 6`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]) * console.log(buf.readUIntBE(0, 6).toString(16)) // Prints: 1234567890ab * })() * ``` */ readUIntBE(offset?: number, byteLength?: number): number; /** * Alias of {@link Buffer.readUIntBE}. * @group Alias Methods */ get readUintBE(): this['readUIntBE']; /** * Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as an unsigned big-endian integer supporting up to 48 bits of accuracy. * @param offset - Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`. * @param byteLength - Number of bytes to read. Must satisfy `0 < byteLength <= 6`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]) * console.log(buf.readUIntLE(0, 6).toString(16)) // Prints: ab9078563412 * })() * ``` */ readUIntLE(offset?: number, byteLength?: number): number; /** * Alias of {@link Buffer.readUIntLE}. * @group Alias Methods */ get readUintLE(): this['readUIntLE']; /** * Reads a 16-bit, big-endian float from `buf` at the specified `offset`. * @param offset - Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * console.log(Buffer.from('0000', 'hex').readFloat16BE(0)) // Prints: 0 * console.log(Buffer.from('8000', 'hex').readFloat16BE(0)) // Prints: -0 * console.log(Buffer.from('3c00', 'hex').readFloat16BE(0)) // Prints: 1 * console.log(Buffer.from('bc00', 'hex').readFloat16BE(0)) // Prints: -1 * console.log(Buffer.from('7c00', 'hex').readFloat16BE(0)) // Prints: Infinity * console.log(Buffer.from('fc00', 'hex').readFloat16BE(0)) // Prints: -Infinity * console.log(Buffer.from('7e00', 'hex').readFloat16BE(0)) // Prints: NaN * console.log(Buffer.from('fe00', 'hex').readFloat16BE(0)) // Prints: NaN * })() * ``` */ readFloat16BE(offset?: number): number; /** * Reads a 16-bit, little-endian float from `buf` at the specified `offset`. * @param offset - Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * console.log(Buffer.from('0000', 'hex').readFloat16LE(0)) // Prints: 0 * console.log(Buffer.from('0080', 'hex').readFloat16LE(0)) // Prints: -0 * console.log(Buffer.from('003c', 'hex').readFloat16LE(0)) // Prints: 1 * console.log(Buffer.from('00bc', 'hex').readFloat16LE(0)) // Prints: -1 * console.log(Buffer.from('007c', 'hex').readFloat16LE(0)) // Prints: Infinity * console.log(Buffer.from('00fc', 'hex').readFloat16LE(0)) // Prints: -Infinity * console.log(Buffer.from('007e', 'hex').readFloat16LE(0)) // Prints: NaN * console.log(Buffer.from('00fe', 'hex').readFloat16LE(0)) // Prints: NaN * })() * ``` */ readFloat16LE(offset?: number): number; /** * Treat `buf` as a [most-significant bit](https://en.wikipedia.org/wiki/Most_significant_bit) array and read a bit at the specified bit offset. * @param bitOffset - bit offset to read from. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from([0b10010110]) * const bits = new Array(8) * for (let i = 0; i < 8; i++) bits[i] = buf.readBitMSB(i) * console.log(bits) // Prints: [1, 0, 0, 1, 0, 1, 1, 0] * })() * ``` */ readBitMSB(bitOffset: number): number; /** * Treat the buffer as a [least significant bit](https://en.wikipedia.org/wiki/Least_significant_bit) array and read a bit at the specified bit offset. * @param bitOffset - bit offset to read from. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from([0b10010110]) * const bits = new Array(8) * for (let i = 0; i < 8; i++) bits[i] = buf.readBitLSB(i) * console.log(bits) // Prints: [0, 1, 1, 0, 1, 0, 0, 1] * })() * ``` */ readBitLSB(bitOffset: number): number; /** * Returns a new `Buffer` that references the same memory as the original, but offset and cropped by the `start` and `end` indexes. * * Specifying `end` greater than `buf.length` will return the same result as that of `end` equal to `buf.length`. * * Modifying the new `Buffer` slice will modify the memory in the original `Buffer` because the allocated memory of the two objects overlap. * * Specifying negative indexes causes the slice to be generated relative to the end of `buf` rather than the beginning. * @group Methods * @param start - Where the new `Buffer` will start. Default: `0`. * @param end - Where the new `Buffer` will end (not inclusive). Default: `buf.length`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.allocUnsafe(26) * for (let i = 0; i < 26; i++) buf1[i] = i + 97 * * const buf2 = buf1.subarray(0, 3) * console.log(buf2.toString('ascii', 0, buf2.length)) // Prints: abc * * buf1[0] = 33 * console.log(buf2.toString('ascii', 0, buf2.length)) // Prints: !bc * })() * ``` * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.allocUnsafe(26) * for (let i = 0; i < 26; i++) buf1[i] = i + 97 * * const buf2 = buf1.subarray(0, 3) * console.log(buf2.toString('ascii', 0, buf2.length)) // Prints: abc * * buf1[0] = 33 * console.log(buf2.toString('ascii', 0, buf2.length)) // Prints: !bc * })() * ``` */ subarray: (start?: number, end?: number) => this; /** * Returns a copy of a portion of a `Buffer` into a new `Buffer` object selected from `start` to `end` (`end` not included) where `start` and `end` represent the index of items in that `buf`. The original `Buffer` will not be modified. * @group Methods * @param start - Where the new `Buffer` will start. Default: `0`. * @param end - Where the new `Buffer` will end (not inclusive). Default: `buf.length`. * @remarks This method is different from Node.js's `Buffer.slice()` method. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('1020304050', 'hex') * const buf2 = buf1.slice(1, 3) * buf1[1] = 0x60 * console.log(buf1.toString('hex')) // Prints: 1060304050 * console.log(buf2.toString('hex')) // Prints: 2030 * })() * ``` */ slice: (start?: number, end?: number) => this; /** * Interprets `buf` as an array of unsigned 16-bit integers and swaps the byte order in-place. * @returns A reference to `buf`. * @throws If `buf.length` is not a multiple of 2, this method will throw a `RangeError`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('0102030405060708', 'hex') * console.log(buf1.toString('hex')) // Prints: 0102030405060708 * buf1.swap16() * console.log(buf1.toString('hex')) // Prints: 0201040306050807 * * const utf16 = Buffer.from('This is little-endian UTF-16', 'utf16le') * utf16.swap16() // Convert to big-endian UTF-16 text. * })() * ``` */ swap16(): this; /** * Interprets `buf` as an array of unsigned 32-bit integers and swaps the byte order in-place. * @returns A reference to `buf`. * @throws If `buf.length` is not a multiple of 4, this method will throw a `RangeError`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('0102030405060708', 'hex') * console.log(buf1.toString('hex')) // Prints: 0102030405060708 * buf1.swap32() * console.log(buf1.toString('hex')) // Prints: 0403020108070605 * })() * ``` */ swap32(): this; /** * Interprets `buf` as an array of unsigned 64-bit integers and swaps the byte order in-place. * @returns A reference to `buf`. * @throws If `buf.length` is not a multiple of 8, this method will throw a `RangeError`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('0102030405060708', 'hex') * console.log(buf1.toString('hex')) // Prints: 0102030405060708 * buf1.swap64() * console.log(buf1.toString('hex')) // Prints: 0807060504030201 * })() * ``` */ swap64(): this; /** * `JSON.stringify()` implicitly calls this method when stringifying a `Buffer` instance. {@link Buffer.from} accepts objects in the format returned from this method. In particular, `Buffer.from(buf.toJSON())` works like `Buffer.from(buf)`. * @returns a JSON representation of `buf`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from('0102030405', 'hex') * const json = JSON.stringify(buf) * console.log(json) // Prints: {"type":"Buffer","data":[1,2,3,4,5]} * * const restored = JSON.parse(json, (key, value) => { * return value && value.type === 'Buffer' ? Buffer.from(value) : value * }) * console.log(restored.toString('hex')) // Prints: 0102030405 * })() * ``` */ toJSON(): { type: 'Buffer'; data: number[]; }; /** * Decodes `buf` to a string according to the specified character encoding in `encoding`. `start` and `end` may be passed to decode only a subset of `buf`. * @param encoding - The character encoding to use. Default: `'utf8'`. * @param start - The byte offset to start decoding at. Default: `0`. * @param end - The byte offset to stop decoding at (not inclusive). Default: `buf.length`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.allocUnsafe(26) * for (let i = 0; i < 26; i++) buf1[i] = i + 97 // 97 is the decimal ASCII value for 'a'. * * console.log(buf1.toString('utf8')) // Prints: abcdefghijklmnopqrstuvwxyz * console.log(buf1.toString('utf8', 0, 5)) // Prints: abcde * * const buf2 = Buffer.from('tést') * console.log(buf2.toString('hex')) // Prints: 74c3a97374 * console.log(buf2.toString('utf8', 0, 3)) // Prints: té * console.log(buf2.toString(undefined, 0, 3)) // Prints: té * })() * ``` */ toString(encoding?: Encoding, start?: number, end?: number): string; /** * Custom inspect functions which `util.inspect()` will invoke and use the result of when inspecting the object. * @returns a string representation of `buf`. * @hidden */ [customInspectSymbol](): string; /** * The method reverses a `Buffer` in place and returns the reference to the same `Buffer`, the first element now becoming the last, and the last element becoming the first. In other words, elements order in the `Buffer` will be turned towards the direction opposite to that previously stated. * @group Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('01020304', 'hex') * buf1.reverse() * console.log(buf1.toString('hex')) // Prints: 04030201 * })() * ``` */ reverse: () => this; /** * The method is the copying counterpart of the `reverse()` method. It returns a new `Buffer` with the elements in reversed order. * @returns A new `Buffer` containing the elements in reversed order. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('01020304', 'hex') * const buf2 = buf1.reverse() * console.log(buf1.toString('hex')) // Prints: 01020304 * console.log(buf2.toString('hex')) // Prints: 04030201 * })() * ``` */ toReversed(): this; /** * Decodes `buf` to a string according to the UCS-2 character encoding. * @param buf - The buffer to decode. * @group Static Methods */ static toUcs2String(buf: Buffer): string; /** * Decodes `buf` to a string according to the UTF-8 character encoding. * @param buf - The buffer to decode. * @see This method based on the [TextDecoder](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/decode) API. * @group Static Methods */ static toUtf8String(buf: Buffer): string; /** * Decodes `buf` to a string according to the Latin1 character encoding. When decoding a `Buffer` into a string, using this encoding will additionally unset the highest bit of each byte before decoding as `'latin1'`. Generally, there should be no reason to use this encoding, as 'utf8' (or, if the data is known to always be ASCII-only, `'latin1'`) will be a better choice when encoding or decoding ASCII-only text. It is only provided for legacy compatibility. * @param buf - The buffer to decode. * @group Static Methods */ static toLatin1String(buf: Buffer): string; /** * Decodes `buf` to a string according to the Base64 character encoding. * @param buf - The buffer to decode. * @group Static Methods */ static toBase64String(buf: Buffer): string; /** * Decodes `buf` to a string according to the Base64 URL character encoding. * @param buf - The buffer to decode. * @group Static Methods */ static toBase64urlString(buf: Buffer): string; /** * Decodes `buf` to a string according to the hexadecimal character encoding. * @param buf - The buffer to decode. * @group Static Methods */ static toHexString(buf: Buffer): string; write(string: string, encoding?: Encoding): number; write(string: string, offset: number, encoding?: Encoding): number; /** * Writes `string` to `buf` at `offset` according to the character encoding in `encoding`. The `length` parameter is the number of bytes to write. If `buf` did not contain enough space to fit the entire string, only part of `string` will be written. However, partially encoded characters will not be written. * @param string - String to write to `buf`. * @param offset - Number of bytes to skip before starting to write `string`. Default: `0`. * @param length - Maximum number of bytes to write (written bytes will not exceed `buf.length - offset`). Default: `buf.length - offset`. * @param encoding - The character encoding of `string`. Default: `'utf8'`. * @returns Number of bytes written. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.alloc(256) * const len1 = buf1.write('\u00bd + \u00bc = \u00be', 0) * console.log(`${len1} bytes: ${buf1.toString('utf8', 0, len1)}`) * // Prints: 12 bytes: ½ + ¼ = ¾ * * const buf2 = Buffer.alloc(10) * const len2 = buf2.write('abcd', 8) * console.log(`${len2} bytes: ${buf2.toString('utf8', 8, 10)}`) * // Prints: 2 bytes : ab * })() * ``` */ write(string: string, offset: number, length: number, encoding?: Encoding): number; /** * Writes `value` to `buf` at the specified `offset` as big-endian. `value` is interpreted and written as a two's complement signed integer. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(8) * buf.writeBigInt64BE(0x0102030405060708n, 0) * console.log(buf.toString('hex')) // Prints: 0102030405060708 * })() * ``` */ writeBigInt64BE(val: bigint, offset?: number): this; /** * Writes `value` to `buf` at the specified `offset` as little-endian. `value` is interpreted and written as a two's complement signed integer. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(8) * buf.writeBigInt64LE(0x0102030405060708n, 0) * console.log(buf.toString('hex')) // Prints: 0807060504030201 * })() * ``` */ writeBigInt64LE(val: bigint, offset?: number): this; /** * Writes `value` to `buf` at the specified `offset` as big-endian. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(8) * buf.writeBigUInt64BE(0xdecafafecacefaden, 0) * console.log(buf.toString('hex')) // Prints: decafafecacefade * })() * ``` */ writeBigUInt64BE(val: bigint, offset?: number): this; /** * Alias of {@link Buffer.writeBigUInt64BE}. * @group Alias Methods */ get writeBigUint64BE(): this['writeBigUInt64BE']; /** * Writes `value` to `buf` at the specified `offset` as little-endian. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(8) * buf.writeBigUInt64LE(0xdecafafecacefaden, 0) * console.log(buf.toString('hex')) // Prints: defacecafefacade * })() * ``` */ writeBigUInt64LE(val: bigint, offset?: number): this; /** * Alias of {@link Buffer.writeBigUInt64LE}. * @group Alias Methods */ get writeBigUint64LE(): this['writeBigUInt64LE']; /** * Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a JavaScript number. Behavior is undefined when `value` is anything other than a JavaScript number. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(8) * buf.writeDoubleBE(123.456, 0) * console.log(buf.toString('hex')) // Prints: 405edd2f1a9fbe77 * })() * ``` */ writeDoubleBE(val: number, offset?: number): this; /** * Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a JavaScript number. Behavior is undefined when `value` is anything other than a JavaScript number. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(8) * buf.writeDoubleLE(123.456, 0) * console.log(buf.toString('hex')) // Prints: 77be9f1a2fdd5e40 * })() * ``` */ writeDoubleLE(val: number, offset?: number): this; /** * Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a JavaScript number. Behavior is undefined when `value` is anything other than a JavaScript number. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 4`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(4) * buf.writeFloatBE(123.456, 0) * console.log(buf.toString('hex')) // Prints: 42f6e979 * })() * ``` */ writeFloatBE(val: number, offset?: number): this; /** * Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a JavaScript number. Behavior is undefined when `value` is anything other than a JavaScript number. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 4`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(4) * buf.writeFloatLE(123.456, 0) * console.log(buf.toString('hex')) // Prints: 79e9f642 * })() * ``` */ writeFloatLE(val: number, offset?: number): this; /** * Writes a 16-bit float `value` to `buf` at the specified `offset` as big-endian. The `value` must be a JavaScript number. Behavior is undefined when `value` is anything other than a JavaScript number. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 2`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(2) * buf.writeFloat16BE(123.456, 0) * console.log(buf.toString('hex')) // Prints: 57b7 * })() * ``` */ writeFloat16BE(val: number, offset?: number): this; /** * Writes a 16-bit float `value` to `buf` at the specified `offset` as little-endian. The `value` must be a JavaScript number. Behavior is undefined when `value` is anything other than a JavaScript number. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 2`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(2) * buf.writeFloat16LE(123.456, 0) * console.log(buf.toString('hex')) // Prints: b757 * })() * ``` */ writeFloat16LE(val: number, offset?: number): this; /** * Writes `value` to `buf` at the specified `offset`. `value` must be a valid signed 8-bit integer. Behavior is undefined when `value` is anything other than a signed 8-bit integer. `value` is interpreted and written as a two's complement signed integer. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 1`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(2) * buf.writeInt8(2, 0) * buf.writeInt8(-2, 1) * console.log(buf.toString('hex')) // Prints: 02fe * })() * ``` */ writeInt8(val: number, offset?: number): this; /** * Writes `value` to `buf` at the specified `offset` as big-endian. The value must be a valid signed 16-bit integer. Behavior is undefined when `value` is anything other than a signed 16-bit integer. The `value` is interpreted and written as a two's complement signed integer. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 2`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(2) * buf.writeInt16BE(0x0102, 0) * console.log(buf.toString('hex')) // Prints: 0102 * })() * ``` */ writeInt16BE(val: number, offset?: number): this; /** * Writes `value` to `buf` at the specified `offset` as little-endian. The value must be a valid signed 16-bit integer. Behavior is undefined when `value` is anything other than a signed 16-bit integer. The `value` is interpreted and written as a two's complement signed integer. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 2`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(2) * buf.writeInt16LE(0x0102, 0) * console.log(buf.toString('hex')) // Prints: 0201 * })() * ``` */ writeInt16LE(val: number, offset?: number): this; /** * Writes `value` to `buf` at the specified `offset` as big-endian. The value must be a valid signed 32-bit integer. Behavior is undefined when `value` is anything other than a signed 32-bit integer. The `value` is interpreted and written as a two's complement signed integer. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 4`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(4) * buf.writeInt32BE(0x01020304, 0) * console.log(buf.toString('hex')) // Prints: 01020304 * })() * ``` */ writeInt32BE(val: number, offset?: number): this; /** * Writes `value` to `buf` at the specified `offset` as little-endian. The value must be a valid signed 32-bit integer. Behavior is undefined when `value` is anything other than a signed 32-bit integer. The `value` is interpreted and written as a two's complement signed integer. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 4`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(4) * buf.writeInt32LE(0x01020304, 0) * console.log(buf.toString('hex')) // Prints: 04030201 * })() * ``` */ writeInt32LE(val: number, offset?: number): this; /** * Writes `byteLength` bytes of `value` to `buf` at the specified `offset` as big-endian. Supports up to 48 bits of accuracy. Behavior is undefined when `value` is anything other than a signed integer. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`. * @param byteLength - Number of bytes to write. Must satisfy `1 <= byteLength <= 6`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(6) * buf.writeIntBE(0x1234567890ab, 0, 6) * console.log(buf.toString('hex')) // Prints: 1234567890ab * })() * ``` */ writeIntBE(val: number, offset?: number, byteLength?: number): this; /** * Writes `byteLength` bytes of `value` to `buf` at the specified `offset` as little-endian. Supports up to 48 bits of accuracy. Behavior is undefined when `value` is anything other than a signed integer. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`. * @param byteLength - Number of bytes to write. Must satisfy `1 <= byteLength <= 6`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(6) * buf.writeIntLE(0x1234567890ab, 0, 6) * console.log(buf.toString('hex')) // Prints: ab9078563412 * })() * ``` */ writeIntLE(val: number, offset?: number, byteLength?: number): this; /** * Writes `value` to `buf` at the specified `offset`. `value` must be a valid unsigned 8-bit integer. Behavior is undefined when `value` is anything other than an unsigned 8-bit integer. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 1`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(4) * buf.writeUInt8(0x3, 0) * buf.writeUInt8(0x4, 1) * buf.writeUInt8(0x23, 2) * buf.writeUInt8(0x42, 3) * console.log(buf.toString('hex')) // Prints: 03042342 * })() * ``` */ writeUInt8(val: number, offset?: number): this; /** * Alias of {@link Buffer.writeUInt8}. * @group Alias Methods */ get writeUint8(): this['writeUInt8']; /** * Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a valid unsigned 16-bit integer. Behavior is undefined when `value` is anything other than an unsigned 16-bit integer. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(4) * buf.writeUInt16BE(0xdead, 0) * buf.writeUInt16BE(0xbeef, 2) * console.log(buf.toString('hex')) // Prints: deadbeef * })() * ``` */ writeUInt16BE(val: number, offset?: number): this; /** * Alias of {@link Buffer.writeUInt16BE}. * @group Alias Methods */ get writeUint16BE(): this['writeUInt16BE']; /** * Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a valid unsigned 16-bit integer. Behavior is undefined when `value` is anything other than an unsigned 16-bit integer. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(4) * buf.writeUInt16LE(0xdead, 0) * buf.writeUInt16LE(0xbeef, 2) * console.log(buf.toString('hex')) // Prints: addeefbe * })() * ``` */ writeUInt16LE(val: number, offset?: number): this; /** * Alias of {@link Buffer.writeUInt16LE}. * @group Alias Methods */ get writeUint16LE(): this['writeUInt16LE']; /** * Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a valid unsigned 32-bit integer. Behavior is undefined when `value` is anything other than an unsigned 32-bit integer. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(4) * buf.writeUInt32BE(0xfeedface, 0) * console.log(buf.toString('hex')) // Prints: feedface * })() * ``` */ writeUInt32BE(val: number, offset?: number): this; /** * Alias of {@link Buffer.writeUInt32BE}. * @group Alias Methods */ get writeUint32BE(): this['writeUInt32BE']; /** * Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a valid unsigned 32-bit integer. Behavior is undefined when `value` is anything other than an unsigned 32-bit integer. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`. Default: `0`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(4) * buf.writeUInt32LE(0xfeedface, 0) * console.log(buf.toString('hex')) // Prints: cefaedfe * })() * ``` */ writeUInt32LE(val: number, offset?: number): this; /** * Alias of {@link Buffer.writeUInt32LE}. * @group Alias Methods */ get writeUint32LE(): this['writeUInt32LE']; /** * Writes `byteLength` bytes of `value` to `buf` at the specified `offset` as big-endian. Supports up to 48 bits of accuracy. Behavior is undefined when `value` is anything other than an unsigned integer. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`. * @param byteLength - Number of bytes to write. Must satisfy `1 <= byteLength <= 6`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(6) * buf.writeUIntBE(0x1234567890ab, 0, 6) * console.log(buf.toString('hex')) // Prints: 1234567890ab * })() * ``` */ writeUIntBE(val: number, offset?: number, byteLength?: number): this; /** * Alias of {@link Buffer.writeUIntBE}. * @group Alias Methods */ get writeUintBE(): this['writeUIntBE']; /** * Writes `byteLength` bytes of `value` to `buf` at the specified `offset` as little-endian. Supports up to 48 bits of accuracy. Behavior is undefined when `value` is anything other than an unsigned integer. * @param val - Number to be written to `buf`. * @param offset - Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`. * @param byteLength - Number of bytes to write. Must satisfy `1 <= byteLength <= 6`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(6) * buf.writeUIntLE(0x1234567890ab, 0, 6) * console.log(buf.toString('hex')) // Prints: ab9078563412 * })() * ``` */ writeUIntLE(val: number, offset?: number, byteLength?: number): this; /** * Alias of {@link Buffer.writeUIntLE}. * @group Alias Methods */ get writeUintLE(): this['writeUIntLE']; /** * Treats `buf` as a [most-significant bit](https://en.wikipedia.org/wiki/Most_significant_bit) array and write a bit at the specified bit offset. * @param val - Bit value to write. * @param bitOffset - bit offset to read from. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(1) * const bits = [1, 0, 0, 1, 0, 1, 1, 0] * for (let i = 0; i < 8; i++) buf.writeBitMSB(bits[i], i) * console.log(buf[0].toString(2)) // Prints: 10010110 * })() * ``` */ writeBitMSB(val: number | boolean, bitOffset: number): this; /** * Treats `buf` as a [least significant bit](https://en.wikipedia.org/wiki/Least_significant_bit) array and write a bit at the specified bit offset. * @param val - Bit value to write. * @param bitOffset - bit offset to read from. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(1) * const bits = [0, 1, 1, 0, 1, 0, 0, 1] * for (let i = 0; i < 8; i++) buf.writeBitLSB(bits[i], i) * console.log(buf[0].toString(2)) // Prints: 10010110 * })() * ``` */ writeBitLSB(val: number | boolean, bitOffset: number): this; /** * Creates an array of chunk `Buffer`s which length is `bytesPerChunk`. If `buf`'s contents can't be split evenly, the final chunk will be the remaining contents. * @param bytesPerChunk - The length of each chunk * @returns The new array of chunks. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from('010203040506070809', 'hex') * console.log(buf.chunk(4).map(chunk => chunk.toString('hex'))) * // Prints: ['01020304', '05060708', '09'] * })() * ``` */ chunk(bytesPerChunk: number): Buffer[]; /** * The method Bitwise NOT every bytes in `this` in place and returns `this`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from('00010203', 'hex') * console.log(buf.not().toString('hex')) // Prints: fffefdfc * console.log(buf.toString('hex')) // Prints: fffefdfc * })() * ``` */ not(): this; /** * The method returns a new `Buffer` which is the Bitwise NOT of `this`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from('00010203', 'hex') * console.log(buf.toNoted().toString('hex')) // Prints: fffefdfc * console.log(buf.toString('hex')) // Prints: 00010203 * })() * ``` */ toNoted(): this; /** * Calculates the Bitwise OR of all bytes in `buf`. If `buf` is empty, returns `0`. You can use {@link Buffer#subarray} to calculate the Bitwise OR of a subset of `buf`. * @returns The Bitwise OR of all bytes in `buf`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from('010203040506070809', 'hex') * console.log(buf.or()) // Prints: 15 * })() * ``` */ or(): number; /** * The method Bitwise OR every bytes with `other` in place and returns `this`. If length of `other` is shorter than `this`, the remaining bytes in `this` will not be changed. If length of `other` is longer than `this`, the remaining bytes in `other` will be ignored. * @param other - A `Buffer` to Bitwise OR with. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('010203', 'hex') * const buf2 = Buffer.from('102030', 'hex') * console.log(buf1.or(buf2).toString('hex')) // Prints: 112233 * console.log(buf1.toString('hex')) // Prints: 112233 * })() * ``` */ or(other: Buffer): this; /** * The method returns a new `Buffer` which is the Bitwise OR of `this` and `other`. If length of `other` is shorter than `this`, the remaining bytes in `this` will be copied to the new `Buffer`. If length of `other` is longer than `this`, the remaining bytes in `other` will be ignored. * @param other - A `Buffer` to Bitwise OR with. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('010203', 'hex') * const buf2 = Buffer.from('102030', 'hex') * console.log(buf1.toOred(buf2).toString('hex')) // Prints: 112233 * console.log(buf1.toString('hex')) // Prints: 010203 * })() * ``` */ toOred(other: Buffer): this; /** * Calculates the Bitwise AND of all bytes in `this`. If `this` is empty, returns `0xFF`. You can use {@link Buffer#subarray} to calculate the Bitwise AND of a subset of `this`. * @returns The Bitwise AND of all bytes in `buf`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from('010203040506070809', 'hex') * console.log(buf.and()) // Prints: 0 * })() * ``` */ and(): number; /** * The method Bitwise AND every bytes with `other` in place and returns `this`. If length of `other` is shorter than `this`, the remaining bytes in `this` will not be changed. If length of `other` is longer than `this`, the remaining bytes in `other` will be ignored. * @param other - A `Buffer` to Bitwise AND with. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('010203', 'hex') * const buf2 = Buffer.from('102030', 'hex') * console.log(buf1.and(buf2).toString('hex')) // Prints: 000000 * console.log(buf1.toString('hex')) // Prints: 000000 * })() * ``` */ and(other: Buffer): this; /** * The method returns a new `Buffer` which is the Bitwise AND of `this` and `other`. If length of `other` is shorter than `this`, the remaining bytes in `this` will be copied to the new `Buffer`. If length of `other` is longer than `this`, the remaining bytes in `other` will be ignored. * @param other - A `Buffer` to Bitwise AND with. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('010203', 'hex') * const buf2 = Buffer.from('102030', 'hex') * console.log(buf1.toAnded(buf2).toString('hex')) // Prints: 000000 * console.log(buf1.toString('hex')) // Prints: 010203 * })() * ``` */ toAnded(other: Buffer): this; /** * Calculates the Bitwise XOR of all bytes in `buf`. If `buf` is empty, returns `0`. You can use {@link Buffer#subarray} to calculate the Bitwise XOR of a subset of `buf`. Xor is usually used to calculate checksums in serial communication. * @returns The Bitwise XOR of all bytes in `buf`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.from('010203040506070809', 'hex') * console.log(buf.xor()) // Prints: 1 * })() * ``` */ xor(): number; /** * The method Bitwise XOR every bytes with `other` in place and returns `this`. If length of `other` is shorter than `this`, the remaining bytes in `this` will not be changed. If length of `other` is longer than `this`, the remaining bytes in `other` will be ignored. * @param other - A `Buffer` to Bitwise XOR with. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('010203', 'hex') * const buf2 = Buffer.from('102030', 'hex') * console.log(buf1.xor(buf2).toString('hex')) // Prints: 112233 * console.log(buf1.toString('hex')) // Prints: 112233 * })() * ``` */ xor(other: Buffer): this; /** * The method returns a new `Buffer` which is the Bitwise XOR of `this` and `other`. If length of `other` is shorter than `this`, the remaining bytes in `this` will be copied to the new `Buffer`. If length of `other` is longer than `this`, the remaining bytes in `other` will be ignored. * @param other - A `Buffer` to Bitwise XOR with. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('010203', 'hex') * const buf2 = Buffer.from('102030', 'hex') * console.log(buf1.toXored(buf2).toString('hex')) // Prints: 112233 * console.log(buf1.toString('hex')) // Prints: 010203 * })() * ``` */ toXored(other: Buffer): this; /** * Pack `vals` into `buf` according to the format string `format`. The arguments must match the `vals` required by the `format` exactly. The `buf`’s size in bytes must larger then the size required by the `format`, as reflected by {@link Buffer.packCalcSize}. * @param format - A format string. Please refer to {@link Buffer.packParseFormat} for more information. * @param vals - Values to pack. * @remarks Unlike Python struct, this method does not support native size and alignment (that wouldn't make much sense in a javascript). Instead, specify byte order and emit pad bytes explicitly. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.alloc(3) * buf1.pack('>h', 0x0102) * console.log(buf1.toString('hex')) // Prints: 010200 * * const buf2 = Buffer.alloc(3) * buf2.subarray(1).pack('>h', 0x0102) // struct.pack_into * console.log(buf2.toString('hex')) // Prints: 000102 * })() * ``` */ pack(format: string, ...vals: any[]): this; /** * Unpack from the `buf` (presumably packed by `pack(format, ...))` according to the format string `format`. The result is a tuple even if it contains exactly one item. The `buf`’s size in bytes must larger then the size required by the `format`, as reflected by {@link Buffer.packCalcSize}. * @param format - A format string. Please refer to {@link Buffer.packParseFormat} for more information. * @remarks Unlike Python struct, this method does not support native size and alignment (that wouldn't make much sense in a javascript). Instead, specify byte order and emit pad bytes explicitly. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('01fe01fe', 'hex') * console.log(buf1.unpack('!BBbb')) // Prints: [1, 254, 1, -2] * })() * ``` */ unpack(format: string): T; /** * Iteratively unpack from the `buf` according to the format string `format`. This method returns an iterator which will read equally sized chunks from the `buf` until remaining contents smaller then the size required by the `format`, as reflected by {@link Buffer.packCalcSize}. * @param format - A format string. Please refer to {@link Buffer.packParseFormat} for more information. * @remarks Unlike Python struct, this method does not support native size and alignment (that wouldn't make much sense in a javascript). Instead, specify byte order and emit pad bytes explicitly. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('01fe01fe', 'hex') * console.log([...buf1.iterUnpack('!BB')]) // Prints: [[1, 254], [1, 254]] * })() * ``` */ iterUnpack(format: string): Generator; /** * The method sorts the elements of a `Buffer` in place and returns the reference to the same `Buffer`, now sorted. * @group Methods * @param compareFn - A function that determines the order of the elements. The function is called with the following arguments: * - `a`: The first element for comparison. * - `b`: The second element for comparison. * It should return a number where: * - A negative value indicates that `a` should come before `b`. * - A positive value indicates that `a` should come after `b`. * - Zero or `NaN` indicates that `a` and `b` are considered equal. * To memorize this, remember that `(a, b) => a - b` sorts numbers in ascending order. If omitted, the elements are sorted according to numeric value. * @returns The reference to the original `Buffer`, now sorted. Note that the `Buffer` is sorted in place, and no copy is made. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('03010204', 'hex') * buf1.sort() * console.log(buf1.toString('hex')) // Prints: 01020304 * * buf1.sort((a, b) => b - a) * console.log(buf1.toString('hex')) // Prints: 04030201 * })() * ``` */ sort: (compareFn?: (a: number, b: number) => any) => this; /** * The method is the copying version of the `sort()` method. It returns a new `Buffer` with the elements sorted in ascending order. * @param compareFn - A function that determines the order of the elements. The function is called with the following arguments: * - `a`: The first element for comparison. * - `b`: The second element for comparison. * It should return a number where: * - A negative value indicates that `a` should come before `b`. * - A positive value indicates that `a` should come after `b`. * - Zero or `NaN` indicates that `a` and `b` are considered equal. * To memorize this, remember that `(a, b) => a - b` sorts numbers in ascending order. If omitted, the elements are sorted according to numeric value. * @returns A new `Buffer` with the elements sorted in ascending order. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('03010204', 'hex') * const buf2 = buf1.toSorted() * console.log(buf1.toString('hex')) // Prints: 03010204 * console.log(buf2.toString('hex')) // Prints: 01020304 * })() * ``` */ toSorted(compareFn?: (a: number, b: number) => any): this; /** * The method is the copying version of using the bracket notation to change the value of a given index. It returns a new `Buffer` with the element at the given index replaced with the given value. * @param index - Zero-based index at which to change the `Buffer`, converted to an integer. * @param value - Any value to be assigned to the given index. * @returns A new `Buffer` with the element at index replaced with value. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.from('0102030405', 'hex') * const buf2 = buf1.with(2, 6) * console.log(buf1.toString('hex')) // Prints: 0102030405 * console.log(buf2.toString('hex')) // Prints: 0102060405 * })() * ``` */ with(index: number, value: number): this; /** * The static method creates a new `Buffer` from a variable number of arguments. * @group Static Methods * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.of(1) * console.log(buf1.toString('hex')) // Prints: 01 * * const buf2 = Buffer.of("1", "2", "3") * console.log(buf2.toString('hex')) // Prints: 010203 * * const buf3 = Buffer.of(undefined) * console.log(buf3.toString('hex')) // Prints: 00 * })() * ``` */ static of: (...items: any[]) => Buffer; /** * Takes an integer value and returns the item at that index, allowing for positive and negative integers. Negative integers count back from the last item in the `Buffer`. * @group Methods * @param index - Zero-based index of the `Buffer` element to be returned, converted to an integer. Negative index counts back from the end of the `Buffer` — if `index < 0`, `index + array.length` is accessed. * @returns The element in the `Buffer` matching the given index. Always returns `undefined` if `index < -array.length` or `index >= array.length` without attempting to access the corresponding property. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.of(1, 2, 4, 7, 11, 18) * console.log(buf.at(-1)) // Expected output: 18 * console.log(buf[buf.length - 1]) // Expected output: 18 * })() * ``` */ at: (index: number) => number | undefined; /** * Tests whether all elements in the `Buffer` pass the test implemented by the provided function. * @group Methods * @param callbackFn - A function to execute for each element in the `Buffer`. It should return a truthy value to indicate the element passes the test, and a falsy value otherwise. The function is called with the following arguments: * - `value`: The current element being processed in the `Buffer`. * - `index`: The index of the current element being processed in the `Buffer`. * - `array`: The `Buffer` `every()` was called upon. * @param thisArg - A value to use as this when executing `callbackFn`. * @returns `true` unless `callbackFn` returns a falsy value for a `Buffer` element, in which case `false` is immediately returned. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * console.log(Buffer.of(12, 5, 8, 130, 44).every(v => v >= 10)) // print: false * console.log(Buffer.of(12, 54, 18, 130, 44).every(v => v >= 10)) // print: true * })() * ``` */ every: (callbackFn: (value: number, index: number, array: this) => unknown, thisArg?: any) => boolean; /** * Creates a copy of a portion of a given `Buffer`, filtered down to just the elements from the given `Buffer` that pass the test implemented by the provided function. * @group Methods * @param callbackFn - A function to execute for each element in the `Buffer`. It should return a truthy value to keep the element in the resulting `Buffer`, and a falsy value otherwise. The function is called with the following arguments: * - `value`: The current element being processed in the `Buffer`. * - `index`: The index of the current element being processed in the `Buffer`. * - `array`: The `Buffer` `filter()` was called upon. * @param thisArg - A value to use as this when executing `callbackFn`. * @returns A copy of the given `Buffer` containing just the elements that pass the test. If no elements pass the test, an empty `Buffer` is returned. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.of(12, 5, 8, 130, 44).filter(v => v >= 10) * console.log(buf.toString('hex')) // Expected output: "0c822c" * })() * ``` */ filter: (callbackFn: (value: number, index: number, array: this) => any, thisArg?: any) => this; /** * Returns the first element in the provided `Buffer` that satisfies the provided testing function. If no values satisfy the testing function, `undefined` is returned. * @group Methods * @param callbackFn - A function to execute for each element in the `Buffer`. It should return a truthy value to indicate a matching element has been found, and a falsy value otherwise. The function is called with the following arguments: * - `value`: The current element being processed in the `Buffer`. * - `index`: The index of the current element being processed in the `Buffer`. * - `array`: The `Buffer` `find()` was called upon. * @param thisArg - A value to use as this when executing `callbackFn`. * @returns The first element in the `Buffer` that satisfies the provided testing function. Otherwise, `undefined` is returned. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * function isPrime(element, index, array) { * let start = 2; * while (start <= Math.sqrt(element)) { * if (element % start++ < 1) { * return false; * } * } * return element > 1; * } * * const buf = Buffer.of(4, 5, 8, 12) * console.log(buf.find(isPrime)) // Expected output: 5 * })() * ``` */ find: (callbackFn: (value: number, index: number, array: this) => any, thisArg?: any) => number | undefined; /** * Returns the index of the first element in the `Buffer` that satisfies the provided testing function. If no elements satisfy the testing function, `-1` is returned. * @group Methods * @param callbackFn - A function to execute for each element in the `Buffer`. It should return a truthy value to indicate a matching element has been found, and a falsy value otherwise. The function is called with the following arguments: * - `value`: The current element being processed in the `Buffer`. * - `index`: The index of the current element being processed in the `Buffer`. * - `array`: The `Buffer` `findIndex()` was called upon. * @param thisArg - A value to use as this when executing `callbackFn`. * @returns The index of the first element in the `Buffer` that passes the test. Otherwise, `-1`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * function isPrime(element, index, array) { * let start = 2; * while (start <= Math.sqrt(element)) { * if (element % start++ < 1) { * return false; * } * } * return element > 1; * } * * console.log(Buffer.of(4, 6, 8, 12).findIndex(isPrime)) // Expected output: -1 * console.log(Buffer.of(4, 6, 7, 12).findIndex(isPrime)) // Expected output: 2 * })() * ``` */ findIndex: (callbackFn: (value: number, index: number, array: this) => any, thisArg?: any) => number; /** * Iterates the `Buffer` in reverse order and returns the value of the first element that satisfies the provided testing function. If no elements satisfy the testing function, undefined is returned. * @group Methods * @param callbackFn - A function to execute for each element in the `Buffer`. It should return a truthy value to indicate a matching element has been found, and a falsy value otherwise. The function is called with the following arguments: * - `value`: The current element being processed in the `Buffer`. * - `index`: The index of the current element being processed in the `Buffer`. * - `array`: The `Buffer` `find()` was called upon. * @param thisArg - A value to use as this when executing `callbackFn`. * @returns The last (highest-index) element in the `Buffer` that satisfies the provided testing function; `undefined` if no matching element is found. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * function isPrime(element, index, array) { * let start = 2; * while (start <= Math.sqrt(element)) { * if (element % start++ < 1) { * return false; * } * } * return element > 1; * } * * const buf1 = Buffer.of(4, 6, 8, 12) * console.log(buf1.findLast(isPrime)) // Expected output: undefined * const buf2 = Buffer.of(4, 5, 7, 8, 9, 11, 12) * console.log(buf2.findLast(isPrime)) // Expected output: 11 * })() * ``` */ findLast: (callbackFn: (value: number, index: number, array: this) => any, thisArg?: any) => number | undefined; /** * Iterates the `Buffer` in reverse order and returns the index of the first element that satisfies the provided testing function. If no elements satisfy the testing function, `-1` is returned. * @group Methods * @param callbackFn - A function to execute for each element in the `Buffer`. It should return a truthy value to indicate a matching element has been found, and a falsy value otherwise. The function is called with the following arguments: * - `value`: The current element being processed in the `Buffer`. * - `index`: The index of the current element being processed in the `Buffer`. * - `array`: The `Buffer` `findIndex()` was called upon. * @param thisArg - A value to use as this when executing `callbackFn`. * @returns The index of the last (highest-index) element in the `Buffer` that passes the test. Otherwise `-1` if no matching element is found. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * function isPrime(element, index, array) { * let start = 2; * while (start <= Math.sqrt(element)) { * if (element % start++ < 1) { * return false; * } * } * return element > 1; * } * * console.log(Buffer.of(4, 6, 8, 12).findLastIndex(isPrime)) // Expected output: -1 * console.log(Buffer.of(4, 5, 7, 8, 9, 11, 12).findLastIndex(isPrime)) // Expected output: 5 * })() * ``` */ findLastIndex: (callbackFn: (value: number, index: number, array: this) => any, thisArg?: any) => number; /** * Returns a string representing the elements of the `Buffer`. The elements are converted to strings using their toLocaleString methods and these strings are separated by a locale-specific string (such as a comma ","). * @group Methods * @param locales - A string with a BCP 47 language tag, or an array of such strings. For the general form and interpretation of the locales argument, see [the parameter description on the Intl main page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument). * @param options - An object with configuration properties. See [Number.prototype.toLocaleString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString). * @returns A string representing the elements of the `Buffer`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.of(200, 50, 81, 12, 42) * console.log(buf.toLocaleString()) // Expected output: "200,50,81,12,42" * console.log(buf.toLocaleString('en-US')) // Expected output: "200,50,81,12,42" * console.log(buf.toLocaleString('ja-JP', { style: 'currency', currency: 'JPY' })) // Expected output: "¥200,¥50,¥81,¥12,¥42" * })() * ``` */ toLocaleString: (locales?: string | string[], options?: Intl.NumberFormatOptions) => string; /** * Executes a provided function once for each `Buffer` element. * @group Methods * @param callbackfn - A function to execute for each element in the `Buffer`. Its return value is discarded. The function is called with the following arguments: * - `value`: The current element being processed in the `Buffer`. * - `index`: The index of the current element being processed in the `Buffer`. * - `array`: The `Buffer` `forEach()` was called upon. * @param thisArg - A value to use as `this` when executing `callbackfn`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * Buffer.of(0, 1, 2, 3).forEach((element, index, array) => { * console.log(`a[${index}] = ${element}`) * }) * // Logs: * // a[0] = 0 * // a[1] = 1 * // a[2] = 2 * // a[3] = 3 * })() * ``` */ forEach: (callbackfn: (value: number, index: number, array: this) => void, thisArg?: any) => void; /** * Creates and returns a new string by concatenating all of the elements in this `Buffer`, separated by commas or a specified separator string. If the `Buffer` has only one item, then that item will be returned without using the separator. * @group Methods * @param separator - A string to separate each pair of adjacent elements of the `Buffer`. If omitted, the `Buffer` elements are separated with a comma `","`. * @returns A string with all `Buffer` elements joined. If `buf.length` is 0, the empty string is returned. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.of(1, 2, 3) * console.log(buf.join()) // Expected output: "1,2,3" * console.log(buf.join(" / ")) // Expected output: "1 / 2 / 3" * console.log(buf.join('')) // Expected output: "123" * })() * ``` */ join: (separator?: string) => string; /** * Creates a new `Buffer` populated with the results of calling a provided function on every element in the calling `Buffer`. * @group Methods * @param callbackfn - A function to execute for each element in the `Buffer`. Its return value is added as a single element in the new `Buffer`. The function is called with the following arguments: * - `value`: The current element being processed in the `Buffer`. * - `index`: The index of the current element being processed in the `Buffer`. * - `array`: The `Buffer` `map()` was called upon. * @param thisArg - A value to use as `this` when executing `callbackfn`. * @returns A new `Buffer` with each element being the result of the callback function. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.of(1, 4, 9) * console.log(buf.map(Math.sqrt).toString('hex')) // Expected output: "010203" * console.log(buf.toString('hex')) // Expected output: "010409" * })() * ``` */ map: (callbackfn: (value: number, index: number, array: this) => number, thisArg?: any) => this; /** * Stores multiple values in the `Buffer`, reading input values from a specified `array`. * @group Methods * @param array - The array from which to copy values. All values from the source `array` are copied into the `Buffer`, unless the length of the source `array` plus the target offset exceeds the length of the `Buffer`, in which case an exception is thrown. If the source `array` is a `Buffer`, the two arrays may share the same underlying ArrayBuffer; the JavaScript engine will intelligently copy the source range of the buffer to the destination range. * @param offset - The offset into the `Buffer` at which to begin writing values from the source `array`. If this value is omitted, 0 is assumed (that is, the source `array` will overwrite values in the `Buffer` starting at index 0). * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = new Buffer(8) * buf.set([1, 2, 3], 3) * console.log(buf.toString('hex')) // Expected output: "0000000102030000" * })() * ``` */ set: (array: this | Uint8Array | ArrayLike, offset?: number) => void; /** * Tests whether at least one element in the `Buffer` passes the test implemented by the provided function. It returns true if, in the `Buffer`, it finds an element for which the provided function returns true; otherwise it returns false. It doesn't modify the `Buffer`. * @group Methods * @param callbackFn - A function to execute for each element in the `Buffer`. It should return a truthy value to indicate the element passes the test, and a falsy value otherwise. The function is called with the following arguments: * - `value`: The current element being processed in the `Buffer`. * - `index`: The index of the current element being processed in the `Buffer`. * - `array`: The `Buffer` `some()` was called upon. * @param thisArg - A value to use as `this` when executing `callbackFn`. * @returns `false` unless callbackFn returns a truthy value for a `Buffer` element, in which case `true` is immediately returned. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const isBiggerThan10 = (value, index, array) => value > 10 * console.log(Buffer.of(2, 5, 8, 1, 4).some(isBiggerThan10)) // Expected output: false * console.log(Buffer.of(12, 5, 8, 1, 4).some(isBiggerThan10)) // Expected output: true * })() * ``` */ some: (callbackFn: (value: number, index: number, array: this) => any, thisArg?: any) => boolean; /** * Returns a new array iterator object that contains the key/value pairs for each index in the `Buffer`. * @group Methods * @returns A new iterable iterator object. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.of(10, 20, 30, 40, 50) * for (const entry of buf.entries()) console.log(entry) * })() * ``` */ entries: () => ArrayIterator<[number, number]>; /** * Returns a new array iterator object that contains the keys for each index in the `Buffer`. * @group Methods * @returns A new iterable iterator object. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.of(10, 20, 30, 40, 50) * for (const key of buf.keys()) console.log(key) * })() * ``` */ keys: () => ArrayIterator; /** * Returns a new array iterator object that iterates the value of each item in the `Buffer`. * @group Methods * @returns A new iterable iterator object. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.of(10, 20, 30, 40, 50) * for (const n of buf1.values()) console.log(n) * * const values = buf1.values() * console.log(values.next().value) // Expected output: 10 * console.log(values.next().value) // Expected output: 20 * console.log(values.next().value) // Expected output: 30 * console.log(values.next().value) // Expected output: 40 * console.log(values.next().value) // Expected output: 50 * })() * ``` */ values: () => ArrayIterator; /** * Implements the iterable protocol and allows `Buffer` to be consumed by most syntaxes expecting iterables, such as the spread syntax and for...of loops. It returns an array iterator object that yields the value of each index in the `Buffer`. * @group Methods * @returns A new iterable iterator object that yields the value of each index in the `Buffer`. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf1 = Buffer.of(10, 20, 30, 40, 50) * for (const n of buf1) console.log(n) * * const values = buf1[Symbol.iterator]() * console.log(values.next().value) // Expected output: 10 * console.log(values.next().value) // Expected output: 20 * console.log(values.next().value) // Expected output: 30 * console.log(values.next().value) // Expected output: 40 * console.log(values.next().value) // Expected output: 50 * })() * ``` */ [Symbol.iterator]: () => ArrayIterator; /** * Calls the specified callback function for all the elements in an array. The return value of * the callback function is the accumulated result, and is provided as an argument in the next * call to the callback function. * @group Methods * @param callbackfn - A function that accepts up to four arguments. The reduce method calls the `callbackfn` function one time for each element in the array. * @param initialValue - If `initialValue` is specified, it is used as the initial value to start the accumulation. The first call to the `callbackfn` function provides this value as an argument instead of an array value. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.of(0, 1, 2, 3) * const result = buf.reduce((accumulator, currentValue) => accumulator + currentValue) * console.log(`result = ${result}`) // result = 6 * })() * ``` */ reduce: (callbackfn: (previousValue: T, currentValue: number, currentIndex: number, array: this) => T, initialValue?: T) => T; /** * Calls the specified callback function for all the elements in an array, in descending order. * The return value of the callback function is the accumulated result, and is provided as an * argument in the next call to the callback function. * @group Methods * @param callbackfn - A function that accepts up to four arguments. The reduceRight method calls * the `callbackfn` function one time for each element in the array. * @param initialValue - If `initialValue` is specified, it is used as the initial value to start * the accumulation. The first call to the `callbackfn` function provides this value as an argument * instead of an array value. * @example * ```js * ;(async function () { * const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm') * * const buf = Buffer.of(10, 20, 30) * const result = buf.reduceRight((accumulator, currentValue) => `${accumulator}, ${currentValue}`) * console.log(result) // Expected output: "30, 20, 10" * })() * ``` */ reduceRight: (callbackfn: (previousValue: T, currentValue: number, currentIndex: number, array: this) => T, initialValue?: T) => T; /** * Alias of {@link DataView.getBigInt64}. */ getBigInt64(byteOffset: number, littleEndian?: boolean): bigint; /** * Alias of {@link DataView.getBigUint64}. */ getBigUint64(byteOffset: number, littleEndian?: boolean): bigint; /** * Polyfill of [DataView.getFloat16](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat16). */ getFloat16(byteOffset: number, littleEndian?: boolean): number; /** * Alias of {@link DataView.getFloat32}. */ getFloat32(byteOffset: number, littleEndian?: boolean): number; /** * Alias of {@link DataView.getFloat64}. */ getFloat64(byteOffset: number, littleEndian?: boolean): number; /** * Alias of {@link DataView.getInt16}. */ getInt16(byteOffset: number, littleEndian?: boolean): number; /** * Alias of {@link DataView.getInt32}. */ getInt32(byteOffset: number, littleEndian?: boolean): number; /** * Alias of {@link DataView.getInt8}. */ getInt8(byteOffset: number): number; /** * Alias of {@link DataView.getUint16}. */ getUint16(byteOffset: number, littleEndian?: boolean): number; /** * Alias of {@link DataView.getUint32}. */ getUint32(byteOffset: number, littleEndian?: boolean): number; /** * Alias of {@link DataView.getUint8}. */ getUint8(byteOffset: number): number; /** * Alias of {@link DataView.setBigInt64}. */ setBigInt64(byteOffset: number, value: bigint, littleEndian?: boolean): this; /** * Alias of {@link DataView.setBigUint64}. */ setBigUint64(byteOffset: number, value: bigint, littleEndian?: boolean): this; /** * Polyfill of [DataView.setFloat16](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat16). */ setFloat16(byteOffset: number, value: number, littleEndian?: boolean): this; /** * Alias of {@link DataView.setFloat32}. */ setFloat32(byteOffset: number, value: number, littleEndian?: boolean): this; /** * Alias of {@link DataView.setFloat64}. */ setFloat64(byteOffset: number, value: number, littleEndian?: boolean): this; /** * Alias of {@link DataView.setInt16}. */ setInt16(byteOffset: number, value: number, littleEndian?: boolean): this; /** * Alias of {@link DataView.setInt32}. */ setInt32(byteOffset: number, value: number, littleEndian?: boolean): this; /** * Alias of {@link DataView.setInt8}. */ setInt8(byteOffset: number, value: number): this; /** * Alias of {@link DataView.setUint16}. */ setUint16(byteOffset: number, value: number, littleEndian?: boolean): this; /** * Alias of {@link DataView.setUint32}. */ setUint32(byteOffset: number, value: number, littleEndian?: boolean): this; /** * Alias of {@link DataView.setUint8}. */ setUint8(byteOffset: number, value: number): this; } interface ArrayLike { readonly length: number; readonly [n: number]: T; } interface PackFormat { littleEndian: boolean; items: Array<[number, string]>; } /** * @hidden */ declare const EncodingConst: readonly ["ucs-2", "utf-16le", "utf-8", "ascii", "base64", "base64url", "binary", "hex", "latin1", "ucs2", "utf16le", "utf8"]; /** * @hidden */ type Encoding = typeof EncodingConst[number]; /** * Alias for T or an object supporting `valueOf: () => T`. * @typeParam T - The type of the value. */ type OrValueOf = T | { valueOf: () => T; }; /** Replace function return type. */ type ReplaceReturnType any, TNewReturn> = (...a: Parameters) => TNewReturn; /** Incompatible functions compare with NodeJS.Buffer */ type KeysIncompatible = 'every' | 'fill' | 'filter' | 'find' | 'findIndex' | 'findLast' | 'findLastIndex' | 'forEach' | 'map' | 'reduce' | 'reduceRight' | 'some'; /** Functions that return this */ type KeysReplaceReturnThis = 'copyWithin' | 'reverse' | 'slice' | 'sort' | 'subarray' | 'swap16' | 'swap32' | 'swap64' | 'valueOf' | 'writeBigInt64BE' | 'writeBigInt64LE' | 'writeBigUint64BE' | 'writeBigUint64LE' | 'writeBigUInt64BE' | 'writeBigUInt64LE' | 'writeDoubleBE' | 'writeDoubleLE' | 'writeFloatBE' | 'writeFloatLE' | 'writeInt8' | 'writeInt16BE' | 'writeInt16LE' | 'writeInt32BE' | 'writeInt32LE' | 'writeIntBE' | 'writeIntLE' | 'writeUint8' | 'writeUint16BE' | 'writeUint16LE' | 'writeUint32BE' | 'writeUint32LE' | 'writeUInt8' | 'writeUInt16BE' | 'writeUInt16LE' | 'writeUInt32BE' | 'writeUInt32LE' | 'writeUintBE' | 'writeUIntBE' | 'writeUintLE' | 'writeUIntLE'; type INodeBuffer = Omit & { [K in KeysReplaceReturnThis]: ReplaceReturnType; }; export { Buffer };