vfs

package
v0.0.0-...-8cba18c Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: MIT Imports: 10 Imported by: 3

README

go-common/vfs

This repository contains the go-common/vfs library.

To install:

go get github.com/ugorji/go-common/vfs

Package Documentation

Package vfs implements a virtual file system.

Exported Package API

var ErrInvalid = os.ErrInvalid
var ErrReadNotImmutable = errors.New("vfs: cannot read immutable contents")
type FS interface{ ... }
type File interface{ ... }
type FileInfo interface{ ... }
type MemFS struct{ ... }
type MemFile struct{ ... }
type OsFS struct{ ... }
    func NewOsFS(fpath string) (z *OsFS, err error)
type Vfs struct{ ... }
type WithReadDir interface{ ... }
type WithReadImmutable interface{ ... }
type ZipFS struct{ ... }
    func NewZipFS(r *zip.ReadCloser) (z *ZipFS)

Documentation

Overview

Package vfs implements a virtual file system.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = os.ErrInvalid
View Source
var ErrReadNotImmutable = errors.New("vfs: cannot read immutable contents")

Functions

This section is empty.

Types

type FS

type FS interface {
	// Open will open a file given its path.
	Open(name string) (File, error)
	// Close will discard resources in use.
	Close() error
	// Matches returns a list of paths within the FS that match a regexp (if defined), and
	// do not match a second regexp (if defined), with an option to include or ignore directories.
	Matches(match, notMatch *regexp.Regexp, includeDirs bool) (names []string, err error)
	// RootFiles defines all the top level files.
	//
	// For example, if there is a filesystem with just 2 files, there's no single root directory
	// but those 2 files are the root files.
	RootFiles() (infos []FileInfo, err error)
}

FS defines the interface for a filesystem (e.g. directory, zip-based, in-memory).

type File

type File interface {
	io.ReadCloser
	Stat() (FileInfo, error)
}

File is an open'ed entry in a file system

type FileInfo

type FileInfo interface {
	Name() string       // base name of the file
	Size() int64        // length in bytes for regular files; system-dependent for others
	ModTime() time.Time // modification time
	IsDir() bool        // abbreviation for Mode().IsDir()
}

FileInfo holds file metadata.

It is intentionally a subset of os.FileInfo, so that it can interop well with the standard lib.

type MemFS

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

func (*MemFS) AddFile

func (x *MemFS) AddFile(parent *MemFile, name string, size int64, modTime time.Time, content string) (m *MemFile)

func (*MemFS) Close

func (x *MemFS) Close() error

func (*MemFS) GetFile

func (x *MemFS) GetFile(name string) *MemFile

func (*MemFS) Matches

func (x *MemFS) Matches(matchRe, notMatchRe *regexp.Regexp, includeDirs bool) (names []string, err error)

func (*MemFS) Open

func (x *MemFS) Open(name string) (f File, err error)

func (*MemFS) RootFiles

func (x *MemFS) RootFiles() (infos []FileInfo, err error)

func (*MemFS) Seal

func (x *MemFS) Seal()

Seal says that we are done modifying the MemFS.

The MemFS can then cache some internal metrics, to optimize things like MemFile.IsDir, etc.

If modification is done to the MemFS after this, the optimizations are removed.

type MemFile

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

func (*MemFile) IsDir

func (x *MemFile) IsDir() bool

func (*MemFile) ModTime

func (x *MemFile) ModTime() time.Time

func (*MemFile) Name

func (x *MemFile) Name() string

func (*MemFile) ReadDir

func (x *MemFile) ReadDir(n int) (infos []FileInfo, err error)

func (*MemFile) ReadImmutable

func (x *MemFile) ReadImmutable() (string, error)

func (*MemFile) Size

func (x *MemFile) Size() int64

func (*MemFile) Stat

func (x *MemFile) Stat() (FileInfo, error)

type OsFS

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

OsFS is a FileSystem that serves files out of a os file

func NewOsFS

func NewOsFS(fpath string) (z *OsFS, err error)

func (*OsFS) Close

func (x *OsFS) Close() error

func (*OsFS) Matches

func (x *OsFS) Matches(matchRe, notMatchRe *regexp.Regexp, includeDirs bool) (names []string, err error)

func (*OsFS) Open

func (x *OsFS) Open(name string) (f File, err error)

func (*OsFS) RootFiles

func (x *OsFS) RootFiles() (infos []FileInfo, err error)

type Vfs

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

Vfs provides a simple virtual file system.

User can request a file from a sequence of directories or zip files, and once it is located, it is returned as a ReadCloser, along with some metadata (like lasModTime, etc).

func (*Vfs) Add

func (vfs *Vfs) Add(failOnMissingFile bool, path string) (err error)

Add a FS to the Vfs based off the path, which is either a directory, a zip file or other file.

Any zip file added is immediately opened for reading right away, and keept it open until Close is explicitly called.

func (*Vfs) Adds

func (vfs *Vfs) Adds(failOnMissingFile bool, paths ...string) (err error)

Adds will call Add(...) on each path passed

func (*Vfs) Close

func (vfs *Vfs) Close() (err error)

Close this Vfs. It is especially useful for the zip type PathInfos in here.

func (*Vfs) Find

func (vfs *Vfs) Find(path string) (f File, err error)

Find a file from the Vfs, given a path. It will try each PathInfo in sequence until it finds the path requested.

func (*Vfs) Matches

func (vfs *Vfs) Matches(matchRe, notMatchRe *regexp.Regexp, includeDirs bool) []string

Find all the paths in this Vfs which match the given reg

type WithReadDir

type WithReadDir interface {
	ReadDir(n int) ([]FileInfo, error)
}

WithReadDir is implemented by Directories to get a listing of the files in them.

type WithReadImmutable

type WithReadImmutable interface {
	ReadImmutable() (string, error)
}

WithReadImmutable is implemented by Files that store their content as an uncompressed immutable string, can provide the ReadImmutable method for efficient use.

type ZipFS

type ZipFS struct {
	*zip.ReadCloser
	// contains filtered or unexported fields
}

ZipFS is a FileSystem that serves files out of a zip file

func NewZipFS

func NewZipFS(r *zip.ReadCloser) (z *ZipFS)

func (*ZipFS) Matches

func (x *ZipFS) Matches(matchRe, notMatchRe *regexp.Regexp, includeDirs bool) (names []string, err error)

func (*ZipFS) Open

func (x *ZipFS) Open(name string) (f File, err error)

func (*ZipFS) RootFiles

func (x *ZipFS) RootFiles() (infos []FileInfo, err error)

Jump to

Keyboard shortcuts

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