file

package
v0.0.0-...-c46dd35 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package file provides atomic file write utilities and platform-specific optimizations. Atomic writes ensure that files are either fully written or not modified, preventing corruption from partial writes or concurrent access. Large files are marked as not needed to optimize page cache behavior on Linux systems.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtomicWrite

func AtomicWrite(path string, data []byte, mode os.FileMode) error

AtomicWrite writes data atomically to a file with the specified permissions. It uses a temporary file in the same directory and atomically renames it to the target path.

func AtomicWriteReader

func AtomicWriteReader(path string, data io.Reader, mode os.FileMode) (retErr error)

AtomicWriteReader writes data from a reader atomically to a file with the specified permissions. It uses a temporary file and atomically renames it, marking large files as not needed for cache optimization.

func Exists

func Exists(name string) bool

Exists checks if a file or directory exists at the given path. It returns false only if the file does not exist; other errors (such as permission denied) return true.

func WriteFileAtomic

func WriteFileAtomic(filePath string, data []byte) error

WriteFileAtomic writes data to a file atomically using a temporary file and rename. It ensures that the file is either fully written with the new data or left unchanged. Data is flushed to disk before the rename operation to ensure durability.

Types

This section is empty.

Jump to

Keyboard shortcuts

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