Function zebra_chain::common::atomic_write
source · pub fn atomic_write(
file_path: PathBuf,
data: &[u8],
) -> Result<Result<PathBuf, PersistError<File>>>
Expand description
Accepts a target file path and a byte-slice.
Atomically writes the byte-slice to a file to avoid corrupting the file if Zebra panics, crashes, or exits while the file is being written, or if multiple Zebra instances try to read and write the same file.
Returns the provided file path if successful.
§Concurrency
This function blocks on filesystem operations and should be called in a blocking task when calling from an async environment.
§Panics
If the provided file_path
is a directory path.