/** UTF-8 BOM bytes */ declare const UTF8_BOM_BYTES: readonly [239, 187, 191]; /** UTF-16 LE BOM bytes */ declare const UTF16_LE_BOM_BYTES: readonly [255, 254]; /** UTF-16 BE BOM bytes */ declare const UTF16_BE_BOM_BYTES: readonly [254, 255]; /** UTF-8 BOM string */ declare const UTF8_BOM = "\uFEFF"; /** * Common binary file signatures. */ declare const BINARY_SIGNATURES: readonly [{ readonly signature: readonly [137, 80, 78, 71]; readonly description: "PNG"; }, { readonly signature: readonly [255, 216, 255]; readonly description: "JPEG"; }, { readonly signature: readonly [71, 73, 70, 56]; readonly description: "GIF"; }, { readonly signature: readonly [80, 75, 3, 4]; readonly description: "ZIP"; }, { readonly signature: readonly [31, 139]; readonly description: "GZIP"; }, { readonly signature: readonly [66, 90, 104]; readonly description: "BZIP2"; }, { readonly signature: readonly [127, 69, 76, 70]; readonly description: "ELF"; }, { readonly signature: readonly [77, 90]; readonly description: "EXE"; }, { readonly signature: readonly [37, 80, 68, 70]; readonly description: "PDF"; }]; /** * Successful text-encoding detection. */ type TextEncodingInfo = { /** Content type indicator */ type: 'text'; /** Character encoding */ encoding: BufferEncoding; /** Whether BOM was detected */ hasBom: boolean; }; /** * Successful binary-content detection. */ type BinaryEncodingInfo = { /** Content type indicator */ type: 'binary'; /** Binary format description */ format?: string; }; /** * Encoding detection result. */ type EncodingInfo = TextEncodingInfo | BinaryEncodingInfo; /** * Detect if content is likely text or binary with encoding information. * * @param buffer - Buffer to analyze * @returns Encoding information * * @example Detecting encoding and BOM info * ```typescript * const buffer = readFileSync('./document.txt') * const info = detectEncodingInfo(buffer) * if (info.type === 'text') { * console.log(`Encoding: ${info.encoding}, BOM: ${info.hasBom}`) * } * ``` */ declare function detectEncodingInfo(buffer: Buffer): EncodingInfo; /** * Detect file encoding from BOM or content analysis. * * @param buffer - Buffer to analyze * @returns Detected encoding, defaults to 'utf-8' * * @example Detecting encoding from buffer * ```typescript * const buffer = readFileSync('./data.txt') * const encoding = detectEncoding(buffer) * const content = buffer.toString(encoding) * ``` */ declare function detectEncoding(buffer: Buffer): BufferEncoding; /** * Check if buffer starts with a BOM. * * @param buffer - Buffer to check * @returns True if buffer has a BOM * * @example Checking if buffer has BOM * ```typescript * const buffer = readFileSync('./file.txt') * if (hasBom(buffer)) { * // Strip BOM before processing * } * ``` */ declare function hasBom(buffer: Buffer): boolean; /** * Check if buffer represents text content. * * @param buffer - Buffer to check * @returns True if the buffer appears to be text * * @example Checking if content is text * ```typescript * const buffer = readFileSync('./unknown-file') * if (isTextFile(buffer)) { * const content = buffer.toString('utf-8') * } * ``` */ declare function isTextFile(buffer: Buffer): boolean; /** * Convert content to UTF-8 string. * * @param content - Buffer or string content * @param sourceEncoding - Source encoding (auto-detected if not provided) * @returns UTF-8 string * * @example Converting a buffer to UTF-8 string * ```typescript * const buffer = Buffer.from('Hello', 'utf-8') * const text = toUtf8(buffer) * // => 'Hello' * ``` */ declare function toUtf8(content: Buffer | string, sourceEncoding?: BufferEncoding): string; /** * Convert buffer to string with encoding detection. * * @param content - Buffer to convert * @param encoding - Optional encoding override (auto-detected if not provided) * @returns Converted string * @throws {Error} If content is binary and cannot be converted * * @example Converting file buffer to string with auto-detection * ```typescript * const fileBuffer = readFileSync('./config.json') * const content = bufferToString(fileBuffer) * // => '{"key": "value"}' * ``` */ declare function bufferToString(content: Buffer, encoding?: BufferEncoding): string; /** * Strip BOM from start of string if present. * * @param content - String that may have BOM * @returns String without BOM * * @example Stripping BOM from a string * ```typescript * const withBom = '\ufeffHello World' * const clean = stripBom(withBom) * // => 'Hello World' * ``` */ declare function stripBom(content: string): string; /** * Add UTF-8 BOM to string if not present. * * @param content - String to add BOM to * @returns String with BOM * * @example Adding UTF-8 BOM to content * ```typescript * const content = 'Hello World' * const withBom = addBom(content) * // => '\ufeffHello World' * ``` */ declare function addBom(content: string): string; export { BINARY_SIGNATURES, UTF16_BE_BOM_BYTES, UTF16_LE_BOM_BYTES, UTF8_BOM, UTF8_BOM_BYTES, addBom, bufferToString, detectEncoding, detectEncodingInfo, hasBom, isTextFile, stripBom, toUtf8 }; export type { EncodingInfo };