mapfs

package module
v0.0.0-...-4a35c07 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2021 License: BSD-3-Clause Imports: 6 Imported by: 1

README

This is a fork of the MapFS component of the Go standard library's testing/fstest package.

It exists to allow me (and anyone else affected) to work around https://github.com/golang/go/issues/46776.

I plan to keep it around forever, for the convenience of anyone depending on it, but I do not plan to maintain it long term, as I hope that upstream fixes will make it unnecessary.

It is released under the same BSD-like license as the Go project.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MapFS

type MapFS map[string]*MapFile

A MapFS is a simple in-memory file system for use in tests, represented as a map from path names (arguments to Open) to information about the files or directories they represent.

The map need not include parent directories for files contained in the map; those will be synthesized if needed. But a directory can still be included by setting the MapFile.Mode's ModeDir bit; this may be necessary for detailed control over the directory's FileInfo or to create an empty directory.

File system operations read directly from the map, so that the file system can be changed by editing the map as needed. An implication is that file system operations must not run concurrently with changes to the map, which would be a race. Another implication is that opening or reading a directory requires iterating over the entire map, so a MapFS should typically be used with not more than a few hundred entries or directory reads.

func (MapFS) Glob

func (fsys MapFS) Glob(pattern string) ([]string, error)

func (MapFS) Open

func (fsys MapFS) Open(name string) (fs.File, error)

Open opens the named file.

func (MapFS) ReadDir

func (fsys MapFS) ReadDir(name string) ([]fs.DirEntry, error)

func (MapFS) ReadFile

func (fsys MapFS) ReadFile(name string) ([]byte, error)

func (MapFS) Stat

func (fsys MapFS) Stat(name string) (fs.FileInfo, error)

func (MapFS) Sub

func (fsys MapFS) Sub(dir string) (fs.FS, error)

type MapFile

type MapFile struct {
	Data    []byte      // file content
	Mode    fs.FileMode // FileInfo.Mode
	ModTime time.Time   // FileInfo.ModTime
	Sys     interface{} // FileInfo.Sys
}

A MapFile describes a single file in a MapFS.

Jump to

Keyboard shortcuts

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