safe

package
v1.53.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileWriter

type FileWriter struct {
	// contains filtered or unexported fields
}

FileWriter is a thread safe writer that does an atomic write to the target file. It allows one writer at a time to acquire a lock, write the file, and atomically replace the contents of the target file.

func CreateFileWriter

func CreateFileWriter(ctx context.Context, path string) (*FileWriter, error)

CreateFileWriter takes path as an absolute path of the target file and creates a new FileWriter by attempting to create a tempfile

func (*FileWriter) Commit

func (fw *FileWriter) Commit() error

Commit will close the temporary file and rename it to the target file name the first call to Commit() will close and delete the temporary file, so subsequenty calls to Commit() are gauaranteed to return an error.

func (*FileWriter) Write

func (fw *FileWriter) Write(p []byte) (n int, err error)

Write wraps the temporary file's Write.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL