mountedfs

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MountedFS

type MountedFS map[string]fs.FS

MountedFS is a `fs.FS` implementation that allows to group together multiple named filesystems and access them as if they are mounted under a virtual root directory, whose entries are names as the filesystems theirself.

mfs := MountedFS{
	"mem1": fstest.MapFS{
		"adir/afile": &fstest.MapFile{Data: data},
	},
	"mem2": fstest.MapFS{
		"adir2/afile2": &fstest.MapFile{Data: data},
	},
}

mfs.Open("mem1/adir/afile")			// returns adir/afile from mem1 fs
mfs.Open("mem2/adir2/afile2")		// returns adir2/afile2 from mem2 fs
mfs.Open("mem2") 					// returns root of mem2
mfs.Open(".") 						// returns a virtual ReadDirFile containing
									// an entry for mem1 and one for mem2

MountedFS implements: * fs.ReadFileFS * fs.StatFS * fs.SubFS * writefs.WriteFS

func (MountedFS) Mount

func (f MountedFS) Mount(name string, fs fs.FS)

Mount add a child file system, using `name` argument as it's mount name.

func (MountedFS) Open

func (f MountedFS) Open(name string) (fs.File, error)

Open opens the named file.

func (MountedFS) OpenFile

func (f MountedFS) OpenFile(name string, flag int, perm fs.FileMode) (writefs.FileWriter, error)

OpenFile implements writefs.WriteFS

func (MountedFS) ReadFile

func (f MountedFS) ReadFile(name string) ([]byte, error)

ReadFile implements fs.ReadFileFS

func (MountedFS) Stat

func (f MountedFS) Stat(name string) (fs.FileInfo, error)

Stat implements fs.StatFS

func (MountedFS) Sub

func (f MountedFS) Sub(dir string) (fs.FS, error)

Sub implements fs.SubFS

Jump to

Keyboard shortcuts

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