fileutil

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package fileutil provides file system utilities including atomic write operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtomicWriteFile

func AtomicWriteFile(path string, data []byte, perm os.FileMode) error

AtomicWriteFile writes data to a file atomically using a temp file + rename pattern. This ensures interrupted writes leave the original file intact.

The caller is responsible for ensuring the parent directory exists. Permissions are applied to the final file via the perm parameter.

func AtomicWriteJSON

func AtomicWriteJSON(path string, v any) error

AtomicWriteJSON writes v as indented JSON to path atomically. Uses 2-space indentation and appends a trailing newline for POSIX compliance.

The caller is responsible for ensuring the parent directory exists. The file is created with 0644 permissions.

func AtomicWriteJSONWithPerm

func AtomicWriteJSONWithPerm(path string, v any, perm os.FileMode) error

AtomicWriteJSON writes v as indented JSON to path atomically with specified permissions. Uses 2-space indentation and appends a trailing newline for POSIX compliance.

The caller is responsible for ensuring the parent directory exists.

func AtomicWriteYAML

func AtomicWriteYAML(path string, v any) (err error)

AtomicWriteYAML writes v as YAML to path atomically. Appends a trailing newline for POSIX compliance.

The caller is responsible for ensuring the parent directory exists. The file is created with 0644 permissions.

func AtomicWriteYAMLWithPerm

func AtomicWriteYAMLWithPerm(path string, v any, perm os.FileMode) (err error)

AtomicWriteYAMLWithPerm writes v as YAML to path atomically with specified permissions. Appends a trailing newline for POSIX compliance.

The caller is responsible for ensuring the parent directory exists.

Types

This section is empty.

Jump to

Keyboard shortcuts

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