atomicfile: Index | Files

package atomicfile

import ""

Package atomicfile provides the ability to write a file with an eventual rename on Close (using os.Rename). This allows for a file to always be in a consistent state and never represent an in-progress write.

NOTE: `os.Rename` may not be atomic on your operating system.


Package Files


type File Uses

type File struct {
    // contains filtered or unexported fields

File behaves like os.File, but does an atomic rename operation at Close.

func New Uses

func New(path string, mode os.FileMode) (*File, error)

New creates a new temporary file that will replace the file at the given path when Closed.

func (*File) Abort Uses

func (f *File) Abort() error

Abort closes the file and removes it instead of replacing the configured file. This is useful if after starting to write to the file you decide you don't want it anymore.

func (*File) Close Uses

func (f *File) Close() error

Close the file replacing the configured file.

Package atomicfile imports 3 packages (graph) and is imported by 14 packages. Updated 2017-07-26. Refresh now. Tools for package owners.