wfs

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package wfs implements interfaces, types and methods for working with an fs.FS you can write to.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInterfaceNotImplemented = errors.New("type does not implement interface")
)

Functions

func Mkdir

func Mkdir(fsys fs.FS, 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 MkdirAll

func MkdirAll(fsys fs.FS, path string, perm fs.FileMode) error

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

func MkdirTemp(fsys fs.FS, path, pattern string) (string, error)

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

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

Remove removes the named file or (empty) directory. If there is an error, it will be of type *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 *PathError.

func WriteFile

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

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

type File interface {
	fs.File
	io.Writer
}

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

func CreateFile(fsys fs.FS, name string) (File, error)

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

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.

Directories

Path Synopsis
Package dirfs provides an implementation of a filesystem (an fs.FS) that is writable.
Package dirfs provides an implementation of a filesystem (an fs.FS) that is writable.

Jump to

Keyboard shortcuts

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