atomicfile

package
v1.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package atomicfile writes files atomically: content is written to a temporary file in the same directory as the destination, then renamed into place. A write that fails partway through (a full disk, a killed process, a crash) leaves the temp file incomplete but never touches the destination, so a good previous artifact is never truncated or corrupted by a failed overwrite — os.Create alone truncates the destination immediately, before a single byte of the new content is written.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Write

func Write(path string, perm os.FileMode, write func(io.Writer) error) error

Write creates parent directories for path as needed, calls write with a temporary file in the same directory, and renames it into place at path only if write and the subsequent close both succeed. perm sets the final file's permissions. A same-directory temp file guarantees the rename is on the same filesystem, so it's atomic.

Types

This section is empty.

Jump to

Keyboard shortcuts

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