/** * Atomic file replacement. * * `fs.writeFile` truncates the target and then streams bytes into it. A crash, * a full disk, or a killed process partway through leaves a truncated file — * and for Decibel that means a half-written issue or epic that no longer * parses. The store's own history has one class of corruption already * (ISS-0129); a partial write is a second, and unlike the first it would not be * recoverable by salvage, because there is nothing to salvage from. * * `rename(2)` within a filesystem is atomic: a concurrent reader sees either * the complete old file or the complete new one, never a mixture. So we write * a sibling temp file, flush it, and rename over the target. * * The temp file must live in the **same directory** as the target. `os.tmpdir()` * is frequently a different filesystem, where rename degrades to copy+unlink * and loses atomicity — silently, which is the worst way to lose it. */ /** * Replace `filePath` with `content` atomically. * * Preserves the existing file's permissions when there is one, so replacing a * record does not quietly widen or narrow its mode. */ export declare function writeFileAtomic(filePath: string, content: string, encoding?: BufferEncoding): Promise; /** * Create `filePath` with `content`, atomically AND exclusively (ISS-0195). * * `writeFile(…, { flag: 'wx' })` is exclusive but not atomic: O_EXCL creates * the file empty and the bytes follow, so a SIGKILL in between leaves a 0-byte * record under a real id. Temp-and-rename is atomic but not exclusive: rename * silently replaces an existing file. `link(2)` is both. It publishes a fully * written, fsynced temp under the final name in one step, and fails with * EEXIST when the name is taken, exactly like O_EXCL. A kill can only leave * the dot-temp behind, which no record scan reads; see sweepAllocationTemps. * * Where hard links are unavailable (some FAT, exFAT and network mounts), this * falls back to the O_EXCL write: still exclusive, and no worse than before. */ export declare function createFileExclusive(filePath: string, content: string, encoding?: BufferEncoding): Promise; /** Suffix of createFileExclusive's temp files. */ export declare const ALLOC_TEMP_SUFFIX = ".alloc.tmp"; /** * Remove createFileExclusive temps in `dir` older than `maxAgeMs`: the debris * a killed writer leaves behind. The age floor keeps it from touching a temp * a live writer is still filling. Never throws; this is housekeeping. */ export declare function sweepAllocationTemps(dir: string, maxAgeMs?: number): Promise; //# sourceMappingURL=atomicWrite.d.ts.map