https://github.com/zserge/atomicwriter
Atomic file writes in Go (using a unique temporary file and atomic rename)
https://github.com/zserge/atomicwriter
Last synced: 2 months ago
JSON representation
Atomic file writes in Go (using a unique temporary file and atomic rename)
- Host: GitHub
- URL: https://github.com/zserge/atomicwriter
- Owner: zserge
- License: mit
- Created: 2015-05-02T13:18:02.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-05-02T13:43:19.000Z (about 11 years ago)
- Last Synced: 2025-04-10T11:36:01.414Z (about 1 year ago)
- Language: Go
- Size: 125 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# atomicwriter
Atomic file writer for Go. It uses a temporary file for writing, and when close
is performed - the temporary file is renamed back to the original file name.
Rename is supposed to be atomic (as it is on most platforms).
Example:
``` go
package main
import (
"log"
"github.com/zserge/atomicwriter"
)
func main() {
f, err := atomicwriter.NewWriter("file.txt")
if err != nil {
log.Panic(err)
}
defer f.Close()
f.Write([]byte("Hello"))
f.Write([]byte("world"))
f.Write([]byte("\n"))
}
```