filesystem

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

The filesystem package exposes some useful function around files, for instance a simple function as `func Exists(src) bool` to verify a file existence easily.

It also exposes `CopyFile(src, dest) error` and `CopyFileWithPerm(src, dest, perm) error` which copy a given src file to dst with either specific permissions or not.

It also exposes `CopyDir(srcdir, destdir)` to copy a full directory at another place. The destination directory will be created if it doesn't already.

The package also exposes some constants around permissions.

Index

Constants

View Source
const (
	// Rw represents a file permission of read/write for current user
	// and no access for user's group and other groups.
	Rw fs.FileMode = 0o600
	// RwRR represents a file permission of read/write for current user
	// and read-only access for user's group and other groups.
	RwRR fs.FileMode = 0o644
	// RwRwRw represents a file permission of read/write for current user
	// and read/write too for user's group and other groups.
	RwRwRw fs.FileMode = 0o666
	// RwxRxRxRx represents a file permission of read/write/execute for current user
	// and read/execute for user's group and other groups.
	RwxRxRxRx fs.FileMode = 0o755
)

Variables

This section is empty.

Functions

func CopyDir added in v2.0.1

func CopyDir(srcdir, destdir string, opts ...FSOption) error

CopyDir copies recursively a provided directory as destdir. It fails if it's a file.

func CopyFile

func CopyFile(src, dest string, opts ...FSOption) error

CopyFile copies a provided file from src to dest with a default permission of 0o644. It fails if it's a directory.

func CopyFileWithPerm

func CopyFileWithPerm(src, dest string, perm fs.FileMode, opts ...FSOption) error

CopyFileWithPerm copies a provided file from src to dest with specific permissions. It fails if it's a directory.

func Exists

func Exists(src string, opts ...FSOption) bool

Exists returns a boolean indicating whether the provided input src exists or not.

Types

type FS added in v2.0.1

type FS interface {
	fs.FS
	fs.ReadDirFS
	fs.ReadFileFS
}

FS represents a filesystem with required minimal functions like Open, ReadDir and ReadFile.

func OS added in v2.0.1

func OS() FS

OS returns an implementation of FS for the current filesystem.

type FSOption added in v2.0.1

type FSOption func(fsOpt *fsOpt)

FSOption represents a function taking an opt client to use filesysem package functions.

func WithFS added in v2.0.1

func WithFS(fsys FS) FSOption

WithFS specifies a FS to read files instead of os filesystem.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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