fileutil

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: MIT Imports: 6 Imported by: 1

README

fileutil

GoDoc

A Go package providing utilities for safe and atomic file operations.

Installation

go get github.com/KarpelesLab/fileutil

Features

  • Put: Conditionally write data only if content differs, with atomic operations
  • WriteFileReader: Atomically write data from an io.Reader using a temporary file with ~ suffix
  • TarExtract: Extract tar archives to a directory

Documentation

Full API documentation is available at pkg.go.dev.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Put added in v0.1.2

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

Put atomically writes data to a file if it doesn't already contain the same content. It returns true if the file was written, false if it already contained the data. The operation is atomic - the file will either be fully written or not modified at all.

func TarExtract

func TarExtract(r io.Reader, targetDir string) error

TarExtract will extract the given input as tar data to the specified directory

This method will not check for anything nefarious. Only use for trusted archives.

func WriteFileReader

func WriteFileReader(name string, data io.Reader, perm os.FileMode) error

WriteFileReader is similar to os.WriteFile but using a Reader instead of a []byte

Types

This section is empty.

Jump to

Keyboard shortcuts

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