fs

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2025 License: MPL-2.0 Imports: 8 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(name string, opts ...Option) (*os.File, error)

func Create

func Create(name string, opts ...Option) (*os.File, error)

func CreateOverwrite

func CreateOverwrite(name string) (*os.File, error)

func DirExists

func DirExists(name string) (bool, error)

func DirExistsJoin

func DirExistsJoin(name ...string) (bool, error)

DirExistsJoin checks if the dir named by segments exists. Segments is a set of path segments that may or may not themselves contain path separators. The following three calls are all equivalent:

DirExistsJoin("some/long/path")
DirExistsJoin("some", "long/path")
DirExistsJoin("some", "long", "path")

func Exists

func Exists(name string) (bool, error)

func FileExists

func FileExists(name string) (bool, error)

FileExists returns a boolean indicating that name is a real path and is not a directory.

func FindFiles

func FindFiles(dir string, predicate FindPredicate) ([]string, error)

FindFiles looks for files in the repo, excluding the .git dir.

func FindFilesNamed

func FindFilesNamed(dir, name string) ([]string, error)

FindFilesNamed returns the paths of all files with the specified name in the file tree rooted at dir.

func Mkdir

func Mkdir(path string) error

Mkdir makes the directory at path, using default permissions.

func MkdirEmpty

func MkdirEmpty(path string) error

MkdirEmpty deletes any existing file or directory at path, and then creates a new empty directory at path, using default permissions.

func Mkdirs

func Mkdirs(paths ...string) error

Mkdirs calls Mkdir sequentially on paths and returns an error after the first failure.

func Move

func Move(oldPath, newPath string, opts ...Option) error

Move is like os.Rename except it first ensures there's nothing at dest by deleting anything there.

func SetMtimes

func SetMtimes(dir string, to time.Time) error

SetMtime sets the mtime of all files inside dir to the provided time.

func WithTempFile

func WithTempFile(name string, do func(io.Writer) error) (string, error)

WithTempFile creates a unique temporary file, runs the 'do' function you provide, passing the file as an io.Writer, and then closes the file. It returns the file's path, or an error from 'do', or a general write or close error.

func WriteFile

func WriteFile[T Bytes](path string, contents T) error

WriteFile writes a file to the specified path, with default permissions, and creates any needed directories.

func WriteTempFile

func WriteTempFile[T Bytes](name string, contents T) (string, error)

WriteTempFile writes contents to a unique temporary file and returns its path.

Types

type Bytes

type Bytes interface {
	[]byte | string
}

type FS

type FS struct {
	Settings
}

func New

func New(opts ...Option) *FS

func (*FS) Append

func (fs *FS) Append(name string) (*os.File, error)

func (*FS) Create

func (fs *FS) Create(name string) (*os.File, error)

func (*FS) Move

func (fs *FS) Move(oldPath, newPath string) error

type FindPredicate

type FindPredicate func(d fs.DirEntry, path string) bool

type Option

type Option func(*Settings)

func WithCreateDirs

func WithCreateDirs(t bool) Option

func WithOverwrite

func WithOverwrite(t bool) Option

type Settings

type Settings struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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