osfs

package
v5.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2024 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FS

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

FS implementation of `fsutil.FS` for the local OS file system.

func New

func New(baseDir string) *FS

New create a new OS file system for the tree of files rooted at the directory "baseDir".

Giving an empty string will use the current working directory as a base. The path is cleaned using `path.Clean()`.

func (*FS) FileExists

func (f *FS) FileExists(name string) bool

FileExists returns true if the file at the given path exists and is readable. Returns false if the given file is a directory.

func (*FS) Getwd

func (*FS) Getwd() (string, error)

Getwd returns a rooted path name corresponding to the current directory. If the current directory can be reached via multiple paths (due to symbolic links), Getwd may return any one of them.

func (*FS) IsDirectory

func (f *FS) IsDirectory(name string) bool

IsDirectory returns true if the file at the given path exists, is a directory and is readable.

func (*FS) Mkdir

func (f *FS) Mkdir(name string, perm fs.FileMode) error

Mkdir creates a new directory with the specified name and permission bits (before umask). If there is an error, it will be of type `*PathError`.

func (*FS) MkdirAll

func (f *FS) MkdirAll(name string, perm fs.FileMode) error

MkdirAll creates a directory, along with any necessary parents, and returns `nil`, or else returns an error. The permission bits perm (before umask) are used for all directories that `MkdirAll` creates. If path is already a directory, `MkdirAll` does nothing and returns `nil`.

func (*FS) Open

func (f *FS) Open(name string) (fs.File, error)

Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode `O_RDONLY`. If there is an error, it will be of type `*PathError“.

func (*FS) OpenFile

func (f *FS) OpenFile(name string, flag int, perm fs.FileMode) (io.ReadWriteCloser, error)

OpenFile is the generalized open call. It opens the named file with specified flag (`O_RDONLY` etc.). If the file does not exist, and the `O_CREATE` flag is passed, it is created with mode perm (before umask). If successful, methods on the returned file can be used for I/O. If there is an error, it will be of type `*PathError`.

func (*FS) ReadDir

func (f *FS) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir reads the named directory, returning all its directory entries sorted by filename. If an error occurs reading the directory, ReadDir returns the entries it was able to read before the error, along with the error.

func (*FS) Remove

func (f *FS) Remove(name string) error

Remove removes the named file or (empty) directory. If there is an error, it will be of type `*PathError`.

func (*FS) RemoveAll

func (f *FS) RemoveAll(name string) error

RemoveAll removes the element at the given path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, `RemoveAll` returns `nil` (no error). If there is an error, it will be of type `*PathError`.

func (*FS) Stat

func (f *FS) Stat(name string) (fs.FileInfo, error)

Stat returns a FileInfo describing the named file. If there is an error, it will be of type `*PathError`.

func (*FS) Sub

func (f *FS) Sub(dir string) (*FS, error)

Sub returns an `*osfs.FS` corresponding to the subtree rooted at this fs's dir. If dir is ".", the same `&osfs.FS` is returned.

Because `*osfs.FS` internally uses the functions from the `os` package, bear in mind that changing the working directory will affect all instances of `*osfs.FS`.

You can't use `Sub` if the current `osfs.FS` has a rooted prefix.

Jump to

Keyboard shortcuts

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