Documentation
¶
Overview ¶
Package fsx extends the fs package with write interfaces.
Index ¶
- func Dir(root string) fs.FS
- func MakeDir(fsys fs.FS, name string, perm fs.FileMode) error
- func OpenFile(fsys fs.FS, name string, flag OpenFlags, perm fs.FileMode) (fs.File, error)
- func Remove(fsys fs.FS, name string) error
- func RemoveAll(fsys fs.FS, name string) error
- func Rename(fsys fs.FS, oldName, newName string) error
- func WriteFile(fsys fs.FS, name string, data []byte, perm fs.FileMode) error
- type LinkError
- type MakeDirFS
- type OpenFileFS
- type OpenFlags
- type RemoveFS
- type RenameFS
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dir ¶
Dir constructs an fs.FS rooted at the specified path.
The result is guaranteed to additionally implement:
func MakeDir ¶
MakeDir creates a new directory in the filesystem with the specified name and permission bits (before umask). It returns an error if the filesystem does not implement MakeDirFS, or if the directory creation fails. If there is an error, it will be of type fs.PathError.
func OpenFile ¶
OpenFile opens the named file in the filesystem with the specified flags (ReadOnly, WriteOnly, ReadWrite, CreateFile, etc.) and permission bits. It returns an error if the filesystem does not implement OpenFileFS, or if the open operation fails. If there is an error, it will be of type fs.PathError.
func Remove ¶
Remove removes the named file or empty directory from the filesystem. It returns an error if the filesystem does not implement RemoveFS, or if the removal fails. If there is an error, it will be of type fs.PathError.
func RemoveAll ¶
RemoveAll removes 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 fs.PathError.
func Rename ¶
Rename renames (moves) a file or directory from oldName to newName in the filesystem. If newName already exists and is not a directory, Rename replaces it. It returns an error if the filesystem does not implement RenameFS, or if the rename operation fails. If there is an error, it will be of type LinkError.
func WriteFile ¶
WriteFile writes data to the named file in the filesystem, creating it if necessary. If the file already exists, WriteFile truncates it before writing. It returns an error if the filesystem does not implement OpenFileFS, if the opened file does not support writing, or if the write operation fails. If there is an error, it will be of type fs.PathError.
Types ¶
type LinkError ¶
LinkError records an error during a link operation involving two paths, such as Rename. It wraps the underlying error and includes both the old and new path names for debugging purposes.
This is an alias for os.LinkError.
type MakeDirFS ¶
MakeDirFS is the interface implemented by a file system that supports creating directories.
MakeDir creates a new directory with the specified name and permission bits (before umask). If there is an error, it will be of type fs.PathError.
type OpenFileFS ¶
type OpenFileFS interface {
OpenFile(name string, flag OpenFlags, perm fs.FileMode) (fs.File, error)
}
OpenFileFS is the interface implemented by a file system that supports opening files with explicit flags and permissions.
OpenFile opens the named file with the specified flag (ReadOnly, ReadWrite, CreateFile, etc.) and permission bits (before umask). Unlike Open, OpenFile can create new files when used with CreateFile and can open files for writing. If successful, methods on the returned file can be used for I/O. If there is an error, it will be of type fs.PathError.
type OpenFlags ¶
type OpenFlags int
OpenFlags are flags to use with OpenFileFS.
const ( // Exactly one of [ReadOnly], [WriteOnly], or [ReadWrite] must be specified. ReadOnly OpenFlags = OpenFlags(os.O_RDONLY) // open the file read-only. WriteOnly OpenFlags = OpenFlags(os.O_WRONLY) // open the file write-only. ReadWrite OpenFlags = OpenFlags(os.O_RDWR) // open the file read-write. // The remaining values may be or'ed in to control behavior. CreateFile OpenFlags = OpenFlags(os.O_CREATE) // create a new file if none exists. CreateExclusive OpenFlags = OpenFlags(os.O_EXCL) // used with O_CREATE, file must not exist. TruncateFile OpenFlags = OpenFlags(os.O_TRUNC) // truncate regular writable file when opened. AppendWrites OpenFlags = OpenFlags(os.O_APPEND) // append data to the file when writing. SyncWrites OpenFlags = OpenFlags(os.O_SYNC) // open for synchronous I/O. )
type RemoveFS ¶
RemoveFS is the interface implemented by a file system that supports removing files and empty directories.
Remove removes the named file or (empty) directory. If there is an error, it will be of type fs.PathError.
type RenameFS ¶
RenameFS is the interface implemented by a file system that supports renaming files and directories.
Rename renames (moves) oldName to newName. If newName already exists and is not a directory, Rename replaces it. OS-specific restrictions may apply when oldName and newName are in different directories. If there is an error, it will be of type LinkError.