/** * Binary Utilities * * Cached TextEncoder/TextDecoder instances and core Uint8Array operations. * Platform-neutral — used across the entire codebase. */ /** * Cached TextEncoder instance for UTF-8 encoding */ export declare const textEncoder: TextEncoder; /** * Cached TextDecoder instance for UTF-8 decoding * ignoreBOM: true - preserves BOM in output to match Node.js behavior */ export declare const textDecoder: TextDecoder; /** * Get a cached TextDecoder instance. * * Note: For the default UTF-8 path we reuse the module-level `textDecoder`. */ export declare function getTextDecoder(encoding?: string): TextDecoder; /** * Create a new TextDecoder instance. * * Use this for streaming decode (`decode(..., { stream: true })`) to avoid * sharing mutable decoder state across concurrent operations. */ export declare function createTextDecoder(encoding?: string): TextDecoder; /** * Minimal streaming decoder interface compatible with a subset of `TextDecoder`. * Used by the browser Readable's `setEncoding()` to support encodings that * `TextDecoder` does not handle (`hex`, `base64`, `base64url`, `ascii`). */ export interface StreamDecoder { decode(input: Uint8Array, options?: { stream?: boolean; }): string; } /** * Create a streaming decoder for the given encoding. * * For encodings natively supported by `TextDecoder` (utf-8, latin1, utf-16le, * etc.) this returns a real `TextDecoder`. For Node.js-only encodings * (`hex`, `base64`, `base64url`, `ascii`) it returns a custom implementation * that matches `StringDecoder` semantics — including stateful buffering for * `base64` (3-byte grouping) and 7-bit masking for `ascii`. */ export declare function createStreamDecoder(encoding?: string): StreamDecoder; /** * Decode a Uint8Array to a string using the given encoding. * * Supports the full set of Node.js Buffer encodings: * `utf8`, `utf-8`, `latin1`, `binary`, `ascii`, `hex`, `base64`, `base64url`, * `utf16le`, `utf-16le`, `ucs2`, `ucs-2`. * * This is the browser-side equivalent of `Buffer.prototype.toString(encoding)`. * All encode paths are pure functions with no shared mutable state. */ export declare function decodeBytesToString(bytes: Uint8Array, encoding?: string): string; /** * Convert string to Uint8Array using cached encoder */ export declare function stringToUint8Array(str: string): Uint8Array; /** * Convert Uint8Array to string using cached decoder */ export declare function uint8ArrayToString(arr: Uint8Array, encoding?: string): string; /** * Concatenate multiple Uint8Arrays efficiently */ export declare function concatUint8Arrays(arrays: readonly Uint8Array[], totalLength?: number): Uint8Array; /** * Compare two Uint8Arrays for equality */ export declare function uint8ArrayEquals(a: Uint8Array, b: Uint8Array): boolean; /** * Find pattern in Uint8Array. * * @param haystack The array to search in * @param needle The pattern to search for * @param start Start index (inclusive, default 0) * @param end End index (exclusive, default haystack.length) — limits the search * region without creating a subarray view */ export declare function uint8ArrayIndexOf(haystack: Uint8Array, needle: Uint8Array, start?: number, end?: number): number; /** * Convert any buffer-like input to Uint8Array */ export declare function toUint8Array(input: string | Uint8Array | ArrayBuffer | number[]): Uint8Array; /** * Convert Uint8Array to a Node.js Buffer view when available. * * In browser environments this returns the original Uint8Array unchanged. */ export declare function uint8ArrayToNodeBufferView(data: Uint8Array): Uint8Array; /** * Convert any input to string */ export declare function anyToString(input: string | Uint8Array | ArrayBuffer | number[], encoding?: string): string; /** * Convert collected chunks to a string. * * Common logic shared by Node.js and browser Collector `toString()`: * - empty → "" * - string chunks → fast path (single return / join) * - binary chunks → decode via the provided `toUint8Array` callback */ export declare function chunksToString(chunks: unknown[], toBytes: () => Uint8Array): string;