Documentation ¶
Overview ¶
Package ctxvfs defines a virtual file system interface whose methods accept a context.Context parameter. It is otherwise similar to golang.org/x/tools/godoc/vfs.
Index ¶
- func ReadAllFiles(ctx context.Context, fs FileSystem, root string, filter func(os.FileInfo) bool) (map[string][]byte, error)
- func ReadFile(ctx context.Context, fs FileSystem, path string) ([]byte, error)
- func StripContext(fs FileSystem) vfs.FileSystem
- type BindMode
- type FileSystem
- type NameSpace
- func (ns NameSpace) Bind(old string, newfs FileSystem, new string, mode BindMode)
- func (ns NameSpace) Fprint(w io.Writer)
- func (ns NameSpace) Lstat(ctx context.Context, path string) (os.FileInfo, error)
- func (ns NameSpace) Open(ctx context.Context, path string) (ReadSeekCloser, error)
- func (ns NameSpace) ReadDir(ctx context.Context, path string) ([]os.FileInfo, error)
- func (ns NameSpace) Stat(ctx context.Context, path string) (os.FileInfo, error)
- func (NameSpace) String() string
- type ReadSeekCloser
- type Walker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadAllFiles ¶
func StripContext ¶
func StripContext(fs FileSystem) vfs.FileSystem
StripContext is an adapter for using a ctxvfs.FileSystem (whose interface methods take a context.Context parameter) as a vfs.FileSystem (whose interface methods DON'T take a context.Context parameter). A context.Background() value is passed to the underlying ctxvfs.FileSystem.
This should only be used temporarily while you are transitioning code to use ctxvfs.FileSystem.
Types ¶
type FileSystem ¶
type FileSystem interface { Open(ctx context.Context, name string) (ReadSeekCloser, error) Lstat(ctx context.Context, path string) (os.FileInfo, error) Stat(ctx context.Context, path string) (os.FileInfo, error) ReadDir(ctx context.Context, path string) ([]os.FileInfo, error) String() string }
The FileSystem interface specifies the methods used to access the file system.
func Map ¶
func Map(m map[string][]byte) FileSystem
Map returns a new FileSystem from the provided map. Map keys should be forward slash-separated pathnames and not contain a leading slash.
It differs from golang.org/x/tools/godoc/vfs/mapfs in the following ways:
- It uses []byte instead of string to hold file contents. This means that callers must synchronize writes (if any) to the byte arrays.
- It implements ctxvfs.FileSystem, not vfs.FileSystem.
func OS ¶
func OS(root string) FileSystem
OS returns an implementation of FileSystem reading from the tree rooted at root. Recording a root is convenient everywhere but necessary on Windows, because the slash-separated path passed to Open has no way to specify a drive letter. Using a root lets code refer to OS(`c:\`), OS(`d:\`) and so on.
TODO(sqs): The ctx parameter in the FileSystem methods is currently ignored.
func SingleFileOverlay ¶
func SingleFileOverlay(fs FileSystem, path string, contents []byte) FileSystem
func Sync ¶
func Sync(mu *sync.Mutex, fs FileSystem) FileSystem
Sync creates a new file system wrapper around fs that locks a mutex during its operations.
The contents of files must be immutable, since it has no way of synchronizing access to the ReadSeekCloser from Open after Open returns.
type NameSpace ¶
type NameSpace map[string][]mountedFS
A NameSpace is a file system made up of other file systems mounted at specific locations in the name space.
It is based on golang.org/x/tools/godoc/vfs Namespace and adds ctx method parameters and the ability to list ancestors of mount points. See that documentation for details.
func (NameSpace) Bind ¶
func (ns NameSpace) Bind(old string, newfs FileSystem, new string, mode BindMode)
type ReadSeekCloser ¶
A ReadSeekCloser can Read, Seek, and Close.
type Walker ¶
type Walker struct {
// contains filtered or unexported fields
}
Walker provides a convenient interface for iterating over the descendants of a filesystem path. Successive calls to the Step method will step through each file or directory in the tree, including the root. The files are walked in lexical order, which makes the output deterministic but means that for very large directories Walker can be inefficient. Walker does not follow symbolic links.
func Walk ¶
func Walk(ctx context.Context, root string, fs FileSystem) *Walker
Walk returns a new Walker rooted at root on the FileSystem fs.
func (*Walker) Err ¶
Err returns the error, if any, for the most recent attempt by Step to visit a file or directory. If a directory has an error, w will not descend into that directory.
func (*Walker) Path ¶
Path returns the path to the most recent file or directory visited by a call to Step. It contains the argument to Walk as a prefix; that is, if Walk is called with "dir", which is a directory containing the file "a", Path will return "dir/a".
func (*Walker) SkipDir ¶
func (w *Walker) SkipDir()
SkipDir causes the currently visited directory to be skipped. If w is not on a directory, SkipDir has no effect.