Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WriteFileAtomic ¶
WriteFileAtomic writes data to path with perm, using tempfile + fsync + rename so a concurrent reader never sees a truncated file and a crash mid-write never leaves a torn file on disk.
Parent directories must already exist — callers that want MkdirAll should call it themselves, to keep this helper one syscall wide.
The tempfile is created in the same directory as path (same filesystem = rename is atomic on POSIX) with prefix derived from filepath.Base(path). On any error after tempfile creation, the tempfile is removed best-effort.
func WriteFileAtomicStream ¶
WriteFileAtomicStream is like WriteFileAtomic but streams into a caller-provided callback. Used for gob/json encoders that want to write directly into the tempfile without materialising the full payload.
err := WriteFileAtomicStream(path, perm, func(w io.Writer) error {
return gob.NewEncoder(w).Encode(v)
})
The writer is buffered; flush is handled by the helper. fsync runs after flush and before rename.
Types ¶
This section is empty.