filesystem

package
v0.0.0-...-c4269dd Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: MIT Imports: 6 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

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 Exists

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

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

Types

type FS

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

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

func OS

func OS() FS

OS returns an implementation of FS for the current filesystem.

type FSOption

type FSOption func(fsOpt *fsOpt)

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

func WithFS

func WithFS(fsys FS) FSOption

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

func WithJoin

func WithJoin(join Join) FSOption

WithJoin specifies a specific function to join a srcdir with one of its files in CopyDir.

func WithPerm

func WithPerm(perm os.FileMode) FSOption

WithPerm specifies the permission for target file for CopyFile and CopyDir.

type Join

type Join func(elems ...string) string

Join represents a function to join multiple elements between them.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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