Documentation
¶
Overview ¶
Package wfs implements interfaces, types and methods for working with an fs.FS you can write to.
Index ¶
- Variables
- func Mkdir(fsys fs.FS, name string, perm fs.FileMode) error
- func MkdirAll(fsys fs.FS, path string, perm fs.FileMode) error
- func MkdirTemp(fsys fs.FS, path, pattern string) (string, error)
- func Remove(fsys fs.FS, name string) error
- func RemoveAll(fsys fs.FS, name string) error
- func WriteFile(fsys fs.FS, name string, data []byte, perm fs.FileMode) error
- type CreateFileFS
- type File
- type MkdirAllFS
- type MkdirFS
- type MkdirTempFS
- type RemoveAllFS
- type RemoveFS
- type WFS
- type WriteFileFS
Constants ¶
This section is empty.
Variables ¶
var (
ErrInterfaceNotImplemented = errors.New("type does not implement interface")
)
Functions ¶
func Mkdir ¶
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 MkdirAll ¶
MkdirAll creates a directory named path, 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 MkdirTemp ¶
MkdirTemp creates a new temporary directory in the directory dir and returns the pathname of the new directory. The new directory's name is generated by adding a random string to the end of pattern. If pattern includes a "*", the random string replaces the last "*" instead. If dir is the empty string, MkdirTemp returns an error. Multiple programs or goroutines calling MkdirTemp simultaneously will not choose the same directory. It is the caller's responsibility to remove the directory when it is no longer needed.
func Remove ¶
Remove removes the named file or (empty) directory. If there is an error, it will be of type *PathError.
Types ¶
type CreateFileFS ¶
type CreateFileFS interface { // Create creates or truncates the named file. If the file already exists, // it is truncated. If the file does not exist, it is created with mode 0666 // (before umask). If successful, methods on the returned File can // be used for I/O; the associated file descriptor has mode O_RDWR. // If there is an error, it will be of type *PathError. CreateFile(name string) (File, error) }
CreateFileFS is the interface implemented by a file system that provides an implementation of CreateFile.
type File ¶
A File provides read and write access to a single file. The File interface is the minimum implementation required of the file. Directory files should also implement ReadDirFile. A file may implement io.ReaderAt or io.Seeker as optimizations.
Unlike an fs.File, a wfs.File also implements the io.Writer interface.
func CreateFile ¶
Create creates or truncates the named file. If the file already exists, it is truncated. If the file does not exist, it is created with mode 0666 (before umask). If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR. If there is an error, it will be of type *PathError.
type MkdirAllFS ¶
type MkdirAllFS interface { fs.FS // MkdirAll creates a directory named path, // 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. MkdirAll(path string, perm fs.FileMode) error }
MkdirAllFS is the interface implemented by a file system that provides an implementation of MkdirAll.
type MkdirFS ¶
type MkdirFS interface { fs.FS // 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. Mkdir(name string, perm fs.FileMode) error }
MkdirFS is the interface implemented by a file system that provides an implementation of Mkdir.
type MkdirTempFS ¶
type MkdirTempFS interface { fs.FS // MkdirTemp creates a new temporary directory in the directory dir // and returns the pathname of the new directory. // The new directory's name is generated by adding a random string to the end of pattern. // If pattern includes a "*", the random string replaces the last "*" instead. // If dir is the empty string, MkdirTemp needs to return an error. // Multiple programs or goroutines calling MkdirTemp simultaneously will not choose the same directory. // It is the caller's responsibility to remove the directory when it is no longer needed. MkdirTemp(path, pattern string) (string, error) }
MkdirTempFS is the interface implemented by a file system that provides an implementation of MkdirTemp.
type RemoveAllFS ¶
type RemoveAllFS interface { fs.FS // 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 *PathError. RemoveAll(path string) error }
RemoveAllFS is the interface implemented by a file system that provides an implementation of RemoveAll.
type RemoveFS ¶
type RemoveFS interface { fs.FS // Remove removes the named file or (empty) directory. // If there is an error, it will be of type *PathError. Remove(name string) error }
RemoveFS is the interface implemented by a file system that provides an implementation of Remove.
type WFS ¶
type WFS interface { fs.FS MkdirFS MkdirAllFS MkdirTempFS CreateFileFS WriteFileFS RemoveFS RemoveAllFS }
A WFS is a writable filesystem that implements fs.FS and other interfaces for writing.
type WriteFileFS ¶
type WriteFileFS interface { fs.FS // WriteFile writes data to the named file, creating it if necessary. // If the file does not exist, WriteFile creates it with permissions perm (before umask); // otherwise WriteFile truncates it before writing, without changing permissions. // Since Writefile requires multiple system calls to complete, a failure mid-operation // can leave the file in a partially written state. WriteFile(name string, data []byte, perm fs.FileMode) error }
WriteFileFS is the interface implemented by a file system that provides an implementation of WriteFile.