safeio

package
v0.0.0-...-720f34a Latest Latest
Warning

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

Go to latest
Published: May 25, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package safeio implements convenient I/O routines that provide additional levels of safety in the presence of unexpected failures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteFile

func WriteFile(filename string, data []byte, perm os.FileMode, ops ...FileOp) error

WriteFile writes data to a file named by filename, atomically.

It's a wrapper to ioutil.WriteFile, but provides atomicity (and increased safety) by writing to a temporary file and renaming it at the end.

Before the final rename, the given ops (if any) are called. They can be used to manipulate the file before it is atomically renamed. If any operation fails, the file is removed and the error is returned.

Note this relies on same-directory Rename being atomic, which holds in most reasonably modern filesystems.

Types

type FileOp

type FileOp func(fname string) error

FileOp represents an operation on a file (passed by its name).

Jump to

Keyboard shortcuts

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