import type { Uint, Int, Int8, Uint8, Int16, Uint16, Float } from './defs'; /** * All encoding algorithms of string */ export type Encoding = 'binary' | 'latin1' | 'ascii' | 'base64' | 'hex' | 'utf-8' | 'utf8' | 'utf-16' | 'utf16' | 'ucs4'; /** * Bytes type */ export type Bytes = Uint8ClampedArray | Uint8Array | Buffer; /** * @class Buffer * This class represents a binary buffer. */ export declare class Buffer extends Uint8Array { /** * Copy current buffer data to the target buffer. * @param target The target buffer to copy data into. * @param targetStart? The starting index in the target buffer, **Default** is 0. * @param sourceStart? The starting index in the source buffer, **Default** is 0. * @param sourceEnd? The ending index in the source buffer, **Default** is the length of the source buffer. * @return The number of bytes copied. * @throws {TypeError} If the target is not a valid typed array. * @throws {RangeError} If the target start index is out of range. * @throws {RangeError} If the source start or end index is out of range. * @example * ```ts * const source = new Buffer([1, 2, 3, 4, 5]); * const target = new Buffer(3); * const bytesCopied = source.copy(target, 0, 1, 4); * console.log(bytesCopied); // Outputs: 3 * console.log(target); // Outputs: Uint8Array(3) [2, 3, 4] * ``` */ copy(target: ArrayBufferView, targetStart?: Uint, sourceStart?: Uint, sourceEnd?: Uint): Uint; /** * slice the buffer data into a new buffer, shared memory with the original buffer. */ slice(start?: Int, end?: Uint): Buffer; /** * filter the buffer data into a new buffer. */ filter(cb: (value: Uint, index: Uint, array: this) => any, thisArg?: any): Buffer; /** * map the buffer data into a new buffer. */ map(cb: (value: Uint, index: Uint, array: this) => Uint, thisArg?: any): Buffer; /** * subarray the buffer data into a new buffer, shared memory with the original buffer. */ subarray(begin?: Int, end?: Uint): Buffer; /** * JSON representation of the buffer. */ toJSON(): { type: 'Buffer'; data: Uint[]; }; /** * writing data to self buffer. */ write(source: ArrayBufferView, offset?: Uint): Uint; /** * Compare this buffer with another buffer or Uint8Array. * @param target The target buffer or Uint8Array to compare with. * @param start? The starting index in the target buffer, **Default** is 0. * @param end? The ending index in the target buffer, **Default** is the length of the target buffer. * @param thisStart? The starting index in this buffer, **Default** is 0. * @param thisEnd? The ending index in this buffer, **Default** is the length of this buffer. * @return {Int} Returns 0 if the buffers are equal, a negative number if this buffer is less than the target, or a positive number if this buffer is greater than the target. * @throws {TypeError} If the target is not a valid typed array. * @throws {RangeError} If the start or end indices are out of range. * @example * ```ts * const buf1 = new Buffer([1, 2, 3]); * const buf2 = new Buffer([1, 2, 3, 4]); * console.log(buf1.compare(buf2)); // Outputs: -1 (buf1 is less than buf2) * console.log(buf2.compare(buf1)); // Outputs: 1 (buf2 is greater than buf1) * console.log(buf1.compare(buf1)); // Outputs: 0 (buf1 is equal to itself) * ``` */ compare(target: Uint8Array, start?: Uint, end?: Uint, thisStart?: Uint, thisEnd?: Uint): Int; /** * Check if this buffer is equal to another buffer or Uint8Array. * @param b The buffer or Uint8Array to compare with. * @return {boolean} Returns true if the buffers are equal, false otherwise. * @throws {TypeError} If the argument is not a valid Uint8Array. * @example * ```ts * const buf1 = new Buffer([1, 2, 3]); * const buf2 = new Buffer([1, 2, 3]); * const buf3 = new Buffer([4, 5, 6]); * console.log(buf1.equals(buf2)); // Outputs: true (buf1 is equal to buf2) * console.log(buf1.equals(buf3)); // Outputs: false (buf1 is not equal to buf3) * ``` */ equals(b: Uint8Array): boolean; /** * Convert the buffer to a string using the specified encoding. * @param encoding? The encoding to use, **Default** is 'utf8'. * @param start? The starting index, **Default** is 0. * @param end? The ending index, **Default** is the length of the buffer. * @return {string} The string representation of the buffer. * @example * ```ts * const buf = new Buffer([72, 101, 108, 108,111]); * console.log(buf.toString('utf8')); // Outputs: Hello * ``` */ toString(encoding?: Encoding, start?: Uint, end?: Uint): string; /** * Read int8 from the buffer at the specified offset. */ readInt8(offset?: Uint): Int8; /** * Read uint8 from the buffer at the specified offset. */ readUInt8(offset?: Uint): Uint8; readInt16BE(offset?: Uint): Int16; readUInt16BE(offset?: Uint): Uint16; readInt32BE(offset?: Uint): Int; readUInt32BE(offset?: Uint): Uint; readInt40BE(offset?: Uint): number; readUInt40BE(offset?: Uint): number; readInt48BE(offset?: Uint): number; readUInt48BE(offset?: Uint): number; readBigInt64BE(offset?: Uint): bigint; readBigUInt64BE(offset?: Uint): bigint; readIntBE(offset?: Uint, byteLength?: number): Int; readUIntBE(offset?: Uint, byteLength?: number): Uint; readInt16LE(offset?: Uint): Int16; readUInt16LE(offset?: Uint): Uint16; readInt32LE(offset?: Uint): Int; readUInt32LE(offset?: Uint): Uint; readInt40LE(offset?: Uint): number; readUInt40LE(offset?: Uint): number; readInt48LE(offset?: Uint): number; readUInt48LE(offset?: Uint): number; readBigInt64LE(offset?: Uint): bigint; readBigUInt64LE(offset?: Uint): bigint; readIntLE(offset?: Uint, byteLength?: number): Int; readUIntLE(offset?: Uint, byteLength?: number): Uint; readFloatBE(offset?: Uint): Float; readFloatLE(offset?: Uint): Float; readDoubleBE(offset?: Uint): number; readDoubleLE(offset?: Uint): number; readBigUIntBE(offset?: Uint, end?: Uint): bigint; readBigUIntLE(offset?: Uint, end?: Uint): bigint; writeInt8(value: Int8, offset?: Uint): Uint; writeUInt8(value: Uint8, offset?: Uint): Uint; writeInt16BE(value: Int16, offset?: Uint): Uint; writeUInt16BE(value: Uint16, offset?: Uint): Uint; writeInt32BE(value: Int, offset?: Uint): Uint; writeUInt32BE(value: Uint, offset?: Uint): Uint; writeInt48BE(value: number, offset?: Uint): Uint; writeUInt48BE(value: number, offset?: Uint): Uint; writeBigInt64BE(value: bigint, offset?: Uint): Uint; writeBigUInt64BE(value: bigint, offset?: Uint): Uint; writeIntBE(value: Int, offset?: Uint, byteLength?: Uint): Uint; writeUIntBE(value: Uint, offset?: Uint, byteLength?: Uint): Uint; writeFloatBE(value: Float, offset?: Uint): Uint; writeFloatLE(value: Float, offset?: Uint): Uint; writeDoubleBE(value: number, offset?: Uint): Uint; writeDoubleLE(value: number, offset?: Uint): Uint; writeBigIntLE(bigint: bigint, offset?: Uint): Uint; } /** * Zero buffer */ export declare const Zero: Buffer; /** * Alloc new buffer */ export declare function alloc(size: Uint, initFill?: Uint): Buffer; /** * Alloc unsafe buffer */ export declare function allocUnsafe(size: Uint): Buffer; /** * Tests whether it is a typed array */ export declare function isTypedArray(arr: any): boolean; /** * Tests whether it is a Uint8Array */ export declare function isUint8Array(arr: any): arr is Uint8Array; /** * Tests whether it is a buffer data type */ export declare function isBuffer(arr: any): arr is Buffer; /** * Compare sizes of two buffers */ export declare function compare(a: Uint8Array, b: Uint8Array): Int; type FromArg = string | ArrayBufferView | ArrayBufferLike | Iterable | ArrayLike; type MapFn = (v: number, k: number) => number; /** * Calculate the length of the string after encoding using the specified algorithm */ export declare function encodeUTF8Length(str: string): Uint; /** * Decode data into a string using the specified algorithm */ export declare function toString(src: Uint8Array, encoding?: Encoding, start?: Uint, end?: Uint): string; /** * Specify the algorithm to encode the string and return the encoded data * @param str The string to encode. * @param targetEn? Optional, the encoding algorithm to use, **Default** is 'utf8'. * @return A Uint8Array containing the encoded data. * @example * ```ts * const encoded = fromString("Hello, World!", "utf8"); * console.log(encoded); // Outputs: Uint8Array(13) [72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33] * ``` */ export declare function fromString(str: string, targetEn?: Encoding): Uint8Array; /** * From string create a buffer * @param from a string to create a buffer from * @param encoding? Optional, this specifies the encoding to use. */ export declare function from(from: string, encoding?: Encoding): Buffer; /** * From ArrayBufferView create a buffer * @param from a TypedArray or DataView to create a buffer from */ export declare function from(from: ArrayBufferView): Buffer; /** * From ArrayBufferLike create a buffer * @param from an ArrayBuffer or SharedArrayBuffer to create a buffer from * @param byteOffset? Optional, the offset in bytes to start from, **Default** is 0. * @param length? Optional, the length in bytes of the buffer, **Default** is the remaining length of the ArrayBuffer. * @example * ```ts * const buffer = from(new ArrayBuffer(10), 0, 10); * console.log(buffer.byteLength); // Outputs: 10 * ``` */ export declare function from(from: ArrayBufferLike, byteOffset?: Uint, length?: Uint): Buffer; /** * From Iterable or ArrayLike create a buffer * @param from an iterable or array-like object to create a buffer from * @param mapFn? Optional, a mapping function to apply to each element. * @example * ```ts * const buffer = from([1, 2, 3, 4], (v, k) => v * 2); * console.log(buffer); // Outputs: Uint8Array(4) [2, 4, 6, 8] * ``` */ export declare function from(from: Iterable | ArrayLike, mapFn?: MapFn): Buffer; /** * Calculate the byte length of a string when encoded with the specified encoding. * @param arg The string whose byte length is to be calculated. * @param encoding? Optional, the encoding to use. If not provided, 'utf8' is assumed. * @return The byte length of the encoded string. * @example * ```ts * const length = byteLength("Hello, World!", "utf8"); * console.log(length); // Outputs: 13 * ``` */ export declare function byteLength(arg: FromArg, encoding?: Encoding): Uint; /** * Concat multiple buffers into a new buffer * @param list An array of byte arrays to concatenate. * @param length? Optional, the total length of the new buffer. If not provided, * it will be calculated based on the lengths of the byte arrays in the list. * @return A new Buffer containing the concatenated data. * @example * ```ts * const buffer1 = new Buffer([1, 2, 3]); * const buffer2 = new Buffer([4, 5, 6]); * const concatenated = concat([buffer1, buffer2]); * console.log(concatenated); // Outputs: Uint8Array(6) [1, 2, 3, 4, 5, 6] * ``` * @throws {TypeError} If the provided list is not an array-like object or if * any of the elements in the list are not of type `Uint8Array` or `Buffer`. * @throws {RangeError} If the specified length is negative. * @throws {Error} If the concatenation fails for any reason. */ export declare function concat(list: ArrayLike[], length?: Uint): Buffer; /** * @default */ declare const _default: { byteLength: typeof byteLength; isBuffer: typeof isBuffer; isTypedArray: typeof isTypedArray; isUint8Array: typeof isUint8Array; from: typeof from; allocUnsafe: typeof allocUnsafe; alloc: typeof alloc; concat: typeof concat; Zero: Buffer; compare: typeof compare; }; export default _default;