Kfg Documentation
    Preparing search index...

    Interface SafeWriteOptions

    Safeguarded file persistence:

    • Lock file prevents two writers from touching the same file at once.
    • Content is written to a temp file, read back and verified BEFORE replacing the target, so disk-full / memory pressure can never corrupt the existing file (you get a clear error instead).
    • Optional backup mirror (allow_backup) kept in sync after every successful write, used to recover a corrupted main file on load.
    interface SafeWriteOptions {
        backup?: string | boolean;
        lockTimeout?: number;
        verify?: (content: string) => boolean;
    }
    Index

    Properties

    backup?: string | boolean

    true (default) → ".bak"; string → custom backup path; false → disabled.

    lockTimeout?: number

    How long (ms) to wait for a concurrent writer to release the lock before failing. Effectively queues writers across processes. Default 1000; 0 fails immediately. Note: the wait blocks the thread (sync API).

    verify?: (content: string) => boolean

    Extra content validation (e.g. JSON.parse) run on the temp file before commit.