Documentation ¶
Overview ¶
Package safe provides safe, atomic saving of files.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type File ¶
File provides safe, atomic saving of files. Instead of truncating and overwriting the destination file, it creates a temporary file in the same directory, writes to it, and then renames the temporary file to the original name when Commit() is called. If Close() is called without calling Commit(), or the Commit() fails, then the original file is left untouched.
func Create ¶
Create creates a temporary file in the same directory as filename, which will be renamed to the given filename when calling Commit.
func CreateWithMode ¶
CreateWithMode creates a temporary file in the same directory as filename, which will be renamed to the given filename when calling Commit.
func (*File) Close ¶
Close the temporary file and remove it, if it hasn't already been committed. If it has been committed, nothing happens.
func (*File) Commit ¶
Commit the data into the original file and remove the temporary file from disk. Close() may still be called, but will do nothing.
func (*File) OriginalName ¶
OriginalName returns the original filename passed into Create().