multifs

package module
v0.0.0-...-7352318 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2022 License: MIT Imports: 7 Imported by: 1

README

multifs

Create an fs.FS instance that "mounts" other fs.FS.

As of this writing this module is really aimed at one-off tools and testing, and thus does not really prioritize on efficiency

Note: extremely alpha quality.

SYNOPSIS

fs1 := ....
fs2 := ....

var fs multifs.FS

fs.Mount("/fs1", fs1)
fs.Mount("/fs2", fs2)

f1, err := fs.Open("/fs1/foo/bar/baz.txt")
f2, err := fs.Open("/fs2/quux/corge/grault.txt")

Path Expansion

Given a prefix of "/prefix", call to (multifs.FS).Open("/prefix/file.txt") results in the backend filesystem receiving "file.txt" as the argument to its Open() method.

This means that you should most likely not just use os.Open in the backend. Instead you should most likely use os.DirFS which takes care of the prefix.

Let's say you have a file name "/root/temp/12345/file.txt". and you want this to be availble in the multifs.FS as "/prefix/file.txt". Then you should do the follwing:

fileFS, _ := os.DirFS("/root/temp/12345")

var fs multifs.FS

fs.Mount("/prefix", fileFS)

The use of os.DirFS makes sure that it takes care of replacing the prefix with the actual file system prefix for you.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FS

type FS struct {
	// contains filtered or unexported fields
}

func New

func New() *FS

New creates an empty multifs.FS object. You will need to call Mount() to add other filesystems

func (*FS) Mount

func (mfs *FS) Mount(prefix string, other fs.FS) error

Mount associates prefix with another fs.FS. For example if you mount "/foo" with an fs.FS that contains files with names such as "/bar/baz.txt", you would be able to access them via "/foo/bar/baz.txt".

Mount currently only understands linux-style paths (technically it uses "path" package).

func (*FS) Open

func (mfs *FS) Open(name string) (fs.File, error)

func (*FS) ReadDir

func (mfs *FS) ReadDir(name string) ([]fs.DirEntry, error)

func (*FS) Stat

func (mfs *FS) Stat(name string) (fs.FileInfo, error)

func (*FS) Unmount

func (mfs *FS) Unmount(prefix string) error

Jump to

Keyboard shortcuts

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