Skip to content

pombredanne/atomicwriter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

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"))
}

About

Atomic file writes in Go (using a unique temporary file and atomic rename)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 94.9%
  • Shell 5.1%