8000 GitHub - sashka/atomicfile: Atomic file writes in Go on Linux, macOS, and Windows.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

sashka/atomicfile

Repository files navigation

atomicfile

Package atomicfile provides *os.File wrapper to allow atomic file writes. Works on Linux, macOS, and Windows.

All writes will go to a temporary file. Call Close() explicitly when you are done writing to atomically rename the file making the changes visible. Call Abort() to discard all your writes.

This allows for a file to always be in a consistent state and never represent an in-progress write.

Installation

Standard go get:

$ go get github.com/sashka/atomicfile

Example

import "github.com/sashka/atomicfile"

// Prepare to write a file.
f, err := atomicfile.New(path, 0o666)

// It's safe to call f.Abort() on a successfully closed file.
// Otherwise it's correct to discard the file changes.
defer f.Abort()

// Update the file.
if _, err := f.Write(content); err != nil {
    return err
}

// Make chan
54D9
ges visible.
f.Close()

About

Atomic file writes in Go on Linux, macOS, and Windows.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0