maybe

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2021 License: Apache-2.0 Imports: 2 Imported by: 19

Documentation

Overview

Package maybe provides a way to atomically create or replace a file, if technically possible.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteFile

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

WriteFile mirrors ioutil.WriteFile. On Linux it uses renameio.WriteFile to create or replace an existing file with the same name atomically. On Windows files cannot be written atomically, so this function falls back to ioutil.WriteFile, which does not write the file atomically and ignores most permission bits. See https://github.com/google/renameio/issues/1 and https://github.com/golang/go/issues/22397#issuecomment-498856679 for discussion.

Prefer using renameio.WriteFile instead so that you get an error if atomic replacement is not possible on the runtime platform. maybe.WriteFile is meant as a convenience wrapper if you are okay with atomic replacement not being supported by the runtime platform.

Types

This section is empty.

Jump to

Keyboard shortcuts

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