readFileStable(filePath: string,read?: (p: string) => Promise<Buffer>): Promise<Buffer>
Reads a file, re-reading until two reads spaced STABILITY_GAP_MS apart return byte-identical
content — so a file caught mid-write (Windows truncate→flush; see STABILITY_GAP_MS) is hashed
only once its bytes have settled. Bounded by MAX_STABILITY_ATTEMPTS; returns the latest content
if it never stabilizes. read is injectable for tests; production reads from disk. Read errors
propagate so the caller's catch can treat a vanished file as a removal.
import * as FileWatcher from './file-watcher.ts'; import { Buffer } from 'node:buffer'; const content = await FileWatcher.readFileStable('/proj/test/cart-test.ts', async () => Buffer.from('settled')); content.toString(); // 'settled' — two reads 10ms apart returned identical bytes