utilio

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanDir

func CleanDir(path string) (retErr error)

CleanDir removes everything in a directory, but not the directory itself.

func DecompressTarGzFromRemote

func DecompressTarGzFromRemote(ctx context.Context, url string) iter.Seq2[*TarFile, error]

DecompressTarGzFromRemote returns an iterator that yields the files contained in a .tar.gz file located at the given URL.

func DownloadToLocalFile

func DownloadToLocalFile(ctx context.Context, url, filename string, perm os.FileMode) error

DownloadToLocalFile downloads content from giving URL to local file and sets the specified permissions. It limits the size of the content to 1 GiB and returns an error if the limit is exceeded. It ensures that the target directory exists and handles the file writing atomically.

NOTE: we assume the filename is trusted and cleaned without path traversal characters.

func DownloadWithSHA256Verification

func DownloadWithSHA256Verification(ctx context.Context, url, checksumURL, filename string, perm os.FileMode) error

DownloadWithSHA256Verification downloads content from the given URL and verifies it against the SHA256 checksum fetched from checksumURL. The checksum file is expected to contain a hex-encoded SHA256 hash (optionally followed by whitespace and a filename, which is ignored).

NOTE: we assume the filename is trusted and cleaned without path traversal characters.

func InstallFile

func InstallFile(filename string, r io.Reader, perm os.FileMode) error

InstallFile writes the content from the provided reader to a local file with specified permissions. It limits the size of the content to 1 GiB and returns an error if the limit is exceeded. It ensures that the target directory exists and handles the file writing atomically.

NOTE: we assume the filename is trusted and cleaned without path traversal characters.

func IsDirEmpty

func IsDirEmpty(dir string) (bool, error)

IsDirEmpty reports whether dir is empty or does not exist.

func IsExecutable

func IsExecutable(filePath string) bool

func WriteFile

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

WriteFile writes the provided content to a local file with specified permissions. It ensures that the target directory exists and handles the file writing atomically.

NOTE: we assume the filename is trusted and cleaned without path traversal characters.

Types

type TarFile

type TarFile struct {
	Name string
	Body io.Reader
}

Jump to

Keyboard shortcuts

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