Help us shape the future of Go! Take the 2026 Go Developer Survey

atomicfile

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2022 License: MIT Imports: 4 Imported by: 39

README

atomicfile

GoDoc

Package atomicfile implements all-or-nothing file replacement by staging output to a temporary file adjacent to the specified target file, and renaming over the target when the temporary is closed.

Documentation

Overview

Package atomicfile implements all-or-nothing file replacement by staging output to a temporary file adjacent to the target, and renaming over the target when the temporary is closed.

If (and only if) the implementation of rename is atomic the replacement is also atomic. Since IEEE Std 1003.1 requires rename to be atomic, this is ordinarily true on POSIX-compatible filesystems.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteAll

func WriteAll(target string, r io.Reader, mode os.FileMode) (int64, error)

WriteAll copies all the data from r to the specified target path via a File. It reports the total number of bytes copied.

func WriteData

func WriteData(target string, data []byte, mode os.FileMode) error

WriteData copies data to the specified target path via a File.

Types

type File

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

A File is a writable temporary file that will be renamed to a target path when successfully closed.

func New

func New(target string, mode os.FileMode) (*File, error)

New constructs a new writable File with the given mode that, when successfully closed will be renamed to target.

func (*File) Cancel

func (f *File) Cancel()

Cancel closes the temporary associated with f and discards it. It is safe to call Cancel even if f.Close has already succeeded.

func (*File) Close

func (f *File) Close() error

Close closes the temporary associated with f and renames it to the designated target file. If closing the temporary fails, or if the rename fails, the temporary file is unlinked before Close returns.

func (*File) Write

func (f *File) Write(data []byte) (int, error)

Write writes data to f, satisfying io.Writer.

Directories

Path Synopsis
cmd
acat command
Program acat copies its standard input to an output file.
Program acat copies its standard input to an output file.

Jump to

Keyboard shortcuts

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