/** * Streaming File Utilities * Provides memory-efficient file operations using streams for large files */ import * as fs from 'fs'; import { Transform } from 'stream'; /** * Adaptive buffer management for optimal memory usage */ declare class AdaptiveBufferManager { private systemMemory; private availableMemory; private bufferSizes; private lastAdjustment; constructor(); /** * Update system memory information */ private updateSystemMemory; /** * Calculate optimal buffer size based on available memory and file type */ calculateOptimalBufferSize(filePath: string, defaultSize?: number): number; /** * Get recommended highWaterMark for streams */ getHighWaterMark(filePath: string, options?: StreamOptions): number; } /** * Stream configuration options */ export interface StreamOptions { highWaterMark?: number; encoding?: BufferEncoding; autoClose?: boolean; emitClose?: boolean; start?: number; end?: number; } /** * File chunk information */ export interface FileChunk { data: Buffer | string; size: number; offset: number; isLast: boolean; } /** * Read large file in chunks using streams * @param filePath - Path to file * @param chunkSize - Size of each chunk in bytes (default: 1MB) * @param options - Stream options * @returns Async iterable of file chunks */ export declare function readFileChunks(filePath: string, chunkSize?: number, options?: StreamOptions): AsyncIterable; /** * Read large file as stream for memory efficiency * @param filePath - Path to file * @param chunkSize - Size of each chunk in bytes (default: 1MB) * @param options - Stream options * @returns Readable stream */ export declare function readFileStream(filePath: string, chunkSize?: number, options?: StreamOptions): fs.ReadStream; /** * Write data to file using streams for memory efficiency * @param filePath - Path to output file * @param source - Source stream or async iterable * @param options - Stream options * @returns Promise that resolves when write is complete */ export declare function writeFileStream(filePath: string, source: NodeJS.ReadableStream | AsyncIterable, options?: StreamOptions): Promise; /** * Transform stream for processing file data */ export declare class FileTransform extends Transform { private transformFn; private encoding; constructor(transformFn: (chunk: Buffer, encoding: BufferEncoding) => Buffer | string, options?: { encoding?: BufferEncoding; }); _transform(chunk: Buffer, encoding: BufferEncoding, callback: Function): void; } /** * Process large file with custom transformation * @param inputPath - Input file path * @param outputPath - Output file path * @param transformFn - Transformation function * @param options - Stream options * @returns Promise that resolves when processing is complete */ export declare function transformFile(inputPath: string, outputPath: string, transformFn: (chunk: Buffer, encoding: BufferEncoding) => Buffer | string, options?: StreamOptions): Promise; /** * Count lines in large file efficiently * @param filePath - Path to file * @param encoding - File encoding (default: utf8) * @returns Promise that resolves to line count */ export declare function countLines(filePath: string, encoding?: BufferEncoding): Promise; /** * Search for pattern in large file efficiently * @param filePath - Path to file * @param pattern - Regular expression pattern to search for * @param maxMatches - Maximum number of matches (default: 100) * @param encoding - File encoding (default: utf8) * @returns Promise that resolves to array of line numbers and matches */ export declare function searchInFile(filePath: string, pattern: RegExp, maxMatches?: number, encoding?: BufferEncoding): Promise>; /** * Copy file using streams for memory efficiency * @param sourcePath - Source file path * @param destPath - Destination file path * @param options - Stream options * @returns Promise that resolves when copy is complete */ export declare function copyFileStream(sourcePath: string, destPath: string, options?: StreamOptions): Promise; /** * Get file size without reading content * @param filePath - Path to file * @returns Promise that resolves to file size in bytes */ export declare function getFileSize(filePath: string): Promise; /** * Check if file is large enough to require streaming * @param filePath - Path to file * @param threshold - Size threshold in bytes (default: 50MB) * @returns Promise that resolves to true if file is large */ export declare function shouldUseStreaming(filePath: string, threshold?: number): Promise; declare const _default: { readFileChunks: typeof readFileChunks; readFileStream: typeof readFileStream; writeFileStream: typeof writeFileStream; FileTransform: typeof FileTransform; transformFile: typeof transformFile; countLines: typeof countLines; searchInFile: typeof searchInFile; copyFileStream: typeof copyFileStream; getFileSize: typeof getFileSize; shouldUseStreaming: typeof shouldUseStreaming; bufferManager: AdaptiveBufferManager; getAdaptiveHighWaterMark: (filePath: string, options?: StreamOptions) => number; calculateOptimalBufferSize: (filePath: string, defaultSize?: number) => number; }; export default _default; //# sourceMappingURL=streamingUtils.d.ts.map