fsx

package
v0.0.0-...-7fce3ab Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2025 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package fsx extends the fs package with write interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dir

func Dir(root string) fs.FS

Dir constructs an fs.FS rooted at the specified path.

The result is guaranteed to additionally implement:

func MakeDir

func MakeDir(fsys fs.FS, name string, perm fs.FileMode) error

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

func OpenFile(fsys fs.FS, name string, flag OpenFlags, perm fs.FileMode) (fs.File, error)

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

func Remove(fsys fs.FS, name string) error

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

func RemoveAll(fsys fs.FS, name string) error

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

func Rename(fsys fs.FS, oldName, newName string) error

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

func WriteFile(fsys fs.FS, name string, data []byte, perm fs.FileMode) error

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

type LinkError = os.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

type MakeDirFS interface {
	MakeDir(name string, perm fs.FileMode) error
}

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

type RemoveFS interface {
	Remove(name string) error
}

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

type RenameFS interface {
	Rename(oldName, newName string) error
}

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.

Jump to

Keyboard shortcuts

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