safeio

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2023 License: Apache-2.0 Imports: 3 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 os.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