vfs

package
v0.12.5 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2020 License: MIT Imports: 13 Imported by: 1

Documentation

Overview

Package vfs provides Virtual FileSystem (VFS) capability. Typically it reflects OS FileSystem behavior in-memory.

aah vfs is Read-Only, even though vfs design nature could support Write operations. I have limited it.

The methods should behave the same as those on an *os.File for Read-Only.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMountExists    = errors.New("vfs: mount already exists")
	ErrMountNotExists = errors.New("vfs: mount does not exist")
	ErrNotAbsolutPath = errors.New("vfs: not a absolute path")
)

VFS errors

Functions

func Glob

func Glob(fs *VFS, pattern string) ([]string, error)

Glob method calls `filepath.Glob` if fs == nil otherwise VFS.

NOTE: Use VFS instance directly `aah.AppVFS().*`. This is created to prevent repetition code in consumimg libraries of aah.

func IsExists

func IsExists(fs *VFS, name string) bool

IsExists method is helper to find existence.

NOTE: Use VFS instance directly `aah.AppVFS().*`. This is created to prevent repetition code in consumimg libraries of aah.

func Lstat

func Lstat(fs *VFS, name string) (os.FileInfo, error)

Lstat method calls `os.Lstat` if fs == nil otherwise VFS.

NOTE: Use VFS instance directly `aah.AppVFS().*`. This is created to prevent repetition code in consumimg libraries of aah.

func ReadDir

func ReadDir(fs *VFS, dirname string) ([]os.FileInfo, error)

ReadDir method calls `ioutil.ReadDir` if fs == nil otherwise VFS.

NOTE: Use VFS instance directly `aah.AppVFS().*`. This is created to prevent repetition code in consumimg libraries of aah.

func ReadFile

func ReadFile(fs *VFS, filename string) ([]byte, error)

ReadFile method calls `ioutil.ReadFile` if fs == nil otherwise VFS.

NOTE: Use VFS instance directly `aah.AppVFS().*`. This is created to prevent repetition code in consumimg libraries of aah.

func Stat

func Stat(fs *VFS, name string) (os.FileInfo, error)

Stat method calls `os.Stat` if fs == nil otherwise VFS.

NOTE: Use VFS instance directly `aah.AppVFS().*`. This is created to prevent repetition code in consumimg libraries of aah.

func Walk

func Walk(fs *VFS, root string, walkFn filepath.WalkFunc) error

Walk method calls `filepath.Walk` if fs == nil otherwise VFS.

NOTE: Use VFS instance directly `aah.AppVFS().*`. This is created to prevent repetition code in consumimg libraries of aah.

Types

type File

type File interface {
	http.File
	Readdirnames(n int) ([]string, error)
}

File interface returned by a vfs.FileSystem's Open method.

func Open

func Open(fs *VFS, name string) (File, error)

Open method calls `os.Open` if fs == nil otherwise VFS.

NOTE: Use VFS instance directly `aah.AppVFS().*`. This is created to prevent repetition code in consumimg libraries of aah.

type FileSystem

type FileSystem interface {
	Open(name string) (File, error)
	Lstat(name string) (os.FileInfo, error)
	Stat(name string) (os.FileInfo, error)
	ReadFile(filename string) ([]byte, error)
	ReadDir(dirname string) ([]os.FileInfo, error)
	Glob(pattern string) ([]string, error)
	IsExists(name string) bool
}

FileSystem interface implements access to a collection of named files. The elements in a file path are separated by slash ('/', U+002F) characters, regardless of host operating system convention.

type Gziper

type Gziper interface {
	RawBytes
	IsGzip() bool
}

Gziper interface is to identify whether the file's raw bytes is gzipped or not.

type Mount

type Mount struct {
	Vroot string
	Proot string
	// contains filtered or unexported fields
}

Mount struct represents mount of single physical directory into virtual directory.

Mount implements `vfs.FileSystem`, its a combination of package `os` and `ioutil` focused on Read-Only operations.

func (*Mount) AddDir

func (m *Mount) AddDir(fi os.FileInfo) error

AddDir method is to add directory node into VFS from mounted source directory.

func (*Mount) AddFile

func (m *Mount) AddFile(fi os.FileInfo, data []byte) error

AddFile method is to add file node into VFS from mounted source directory.

func (Mount) Glob

func (m Mount) Glob(pattern string) ([]string, error)

Glob method somewhat similar to `filepath.Glob`, since aah vfs does pattern match only on `filepath.Base` value.

func (Mount) IsExists

func (m Mount) IsExists(name string) bool

IsExists method is helper to find existence.

func (Mount) Lstat

func (m Mount) Lstat(name string) (os.FileInfo, error)

Lstat method behaviour is same as `os.Lstat`.

func (*Mount) Name

func (m *Mount) Name() string

Name method returns mounted path.

func (Mount) Open

func (m Mount) Open(name string) (File, error)

Open method behaviour is same as `os.Open`.

func (Mount) ReadDir

func (m Mount) ReadDir(dirname string) ([]os.FileInfo, error)

ReadDir method behaviour is same as `ioutil.ReadDir`.

func (Mount) ReadFile

func (m Mount) ReadFile(name string) ([]byte, error)

ReadFile method behaviour is same as `ioutil.ReadFile`.

func (Mount) Stat

func (m Mount) Stat(name string) (os.FileInfo, error)

Stat method behaviour is same as `os.Stat`

func (Mount) String

func (m Mount) String() string

String method Stringer interface.

type NodeInfo

type NodeInfo struct {
	Dir      bool
	DataSize int64
	Path     string
	Time     time.Time
}

NodeInfo is used to collect `os.FileInfo` values during binary generation.

func (NodeInfo) IsDir

func (n NodeInfo) IsDir() bool

IsDir method returns whether node is dierctory or not.

func (NodeInfo) ModTime

func (n NodeInfo) ModTime() time.Time

ModTime method returns modification time.

func (NodeInfo) Mode

func (n NodeInfo) Mode() os.FileMode

Mode method returns file mode bits.

func (NodeInfo) Name

func (n NodeInfo) Name() string

Name method returns base name of the file/directory.

func (NodeInfo) Size

func (n NodeInfo) Size() int64

Size method returns length in bytes for regular files; system-dependent for others

func (NodeInfo) Sys

func (n NodeInfo) Sys() interface{}

Sys method returns nil.

type RawBytes

type RawBytes interface {
	RawBytes() []byte
}

RawBytes interface is to retrieve underlying file's raw bytes.

Note: It could be gzip or non-gzip bytes. Use interface `Gziper` to identify byte classification.

type VFS

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

VFS represents Virtual FileSystem (VFS), it operates in-memory. if file/directory doesn't exists on in-memory then it tries physical filesystem.

VFS implements `vfs.FileSystem`, its a combination of package `os` and `ioutil` focused on Read-Only operations.

Single point of access for all mounted virtual directories in aah application.

func (*VFS) AddMount

func (v *VFS) AddMount(mountPath, physicalPath string) error

AddMount method used to mount physical directory as a virtual mounted directory.

Basically aah scans and application source files and builds each file from mounted source directory into binary for single binary build.

func (*VFS) Dirs

func (v *VFS) Dirs(root string) ([]string, error)

Dirs method returns directories path recursively for given root path.

func (*VFS) Files

func (v *VFS) Files(root string) ([]string, error)

Files method returns directories path recursively for given root path.

func (*VFS) FindMount

func (v *VFS) FindMount(name string) (*Mount, error)

FindMount method finds the mounted virtual directory by mount path. if found then returns `Mount` instance otherwise nil and error.

Mount implements `vfs.FileSystem`, its a combination of package `os` and `ioutil` focused on Read-Only operations.

func (*VFS) Glob

func (v *VFS) Glob(pattern string) ([]string, error)

Glob method somewhat similar to `filepath.Glob`, since aah vfs does pattern match only on `filepath.Base` value.

func (*VFS) IsEmbeddedMode

func (v *VFS) IsEmbeddedMode() bool

IsEmbeddedMode method returns true if its a single binary otherwise false.

func (*VFS) IsExists

func (v *VFS) IsExists(name string) bool

IsExists method is helper to find existence.

func (*VFS) Lstat

func (v *VFS) Lstat(name string) (os.FileInfo, error)

Lstat method behaviour is same as `os.Lstat`.

func (*VFS) Open

func (v *VFS) Open(name string) (File, error)

Open method behaviour is same as `os.Open`.

func (*VFS) ReadDir

func (v *VFS) ReadDir(dirname string) ([]os.FileInfo, error)

ReadDir method behaviour is same as `ioutil.ReadDir`.

func (*VFS) ReadFile

func (v *VFS) ReadFile(filename string) ([]byte, error)

ReadFile method behaviour is same as `ioutil.ReadFile`.

func (*VFS) SetEmbeddedMode

func (v *VFS) SetEmbeddedMode()

SetEmbeddedMode method set the VFS into Embedded Mode. It means single binary.

func (*VFS) Stat

func (v *VFS) Stat(name string) (os.FileInfo, error)

Stat method behaviour is same as `os.Stat`

func (*VFS) Walk

func (v *VFS) Walk(root string, walkFn filepath.WalkFunc) error

Walk method behaviour is same as `filepath.Walk`.

Jump to

Keyboard shortcuts

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