A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/sashka/atomicfile below:

sashka/atomicfile: Atomic file writes in Go on Linux, macOS, and Windows.

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.

Standard go get:

$ go get github.com/sashka/atomicfile
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 changes visible.
f.Close()

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4