safeio

package
v0.0.0-...-63ef27d Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: MIT 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