A crate for safely writing files using an atomic write pattern.
This crate implements a safe file writing strategy that helps prevent file corruption in case of system crashes or power failures. It follows these steps:
- Creates parent directories if they don't exist
- Writes content to a temporary file
- Ensures the content is fully written to disk
- Atomically renames the temporary file to the target path
Examples
use safe_write;
let content = b"Hello, World!";
safe_write.expect;
Platform-specific behavior
On Windows, if the target file exists, it will be explicitly removed before the rename operation since Windows doesn't support atomic file replacement.