func WriteFile(path string, data []byte) error
Write bytes to a file, using write-rename when appropriate
File-like interface used by several functions in this package. Some of them may open a file or stdio directly without atomic semantics, in which case Commit() is an alias for Close()
type AtomicFile interface { io.Reader io.ReaderAt io.Writer io.WriterAt io.Seeker Truncate(size int64) error // Close and unlink the underlying file object, discarding the contents. // No-op if Close() or Commit() was already called. io.Closer // Get the underlying *File object GetFile() *os.File // Complete the write-rename pattern and close the file Commit() error }
func New(name string) (AtomicFile, error)
Open a temporary file for reading and writing which will ultimately be renamed to the given name when Commit() is called.
func WriteAny(path string) (AtomicFile, error)
Pick the best strategy for writing to the given path. Pipes and devices will be written to directly, otherwise write-rename.
func WriteInPlace(src *os.File, dest string) (AtomicFile, error)
If src and dest are the same, use src for reading and writing. If they are different, make a copy and open the destination as an atomicfile, after which src will be closed.