vfs

package module
v0.0.0-...-82c8a6b Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2023 License: Apache-2.0 Imports: 16 Imported by: 11

README

Virtual File System

Golang virtual file system based on afero

usage

go get github.com/goxiaoy/vfs

v := vfs.New() //vfs implements afero.Fs

v.Mount("/", afero.NewMemMapFs()) //second prameter could be any afero.Fs 
v.Mount("/abc", afero.NewMemMapFs())
v.Mount("/a/b/c/d", afero.NewMemMapFs())

f,err := v.Create("/a/test.txt") // Creat file, for all functions see https://github.com/spf13/afero#list-of-all-available-functions

Blob

Extra blob interface

type Blob interface {
	FS
	Linker
	//TODO
	//Mover
	//Copier
	//Lister
}

Planned Features

  • Metadata storage
  • Data At Rest Encryption (DARE)

Thanks to

https://github.com/embeddedgo/go

https://github.com/spf13/afero

https://pkg.go.dev/gocloud.dev/blob

https://github.com/dghubble/trie

Documentation

Index

Constants

View Source
const (
	Name = "vfs"
)

Variables

View Source
var (
	ErrRecursive    = errors.New("recursive mount may cause dead lock")
	ErrNotSupported = errors.New("not supported")
)

Functions

func CopyDir

func CopyDir(srcFs FS, srcDirPath string, destFs FS, destDirPath string) error

CopyDir slow copy dir across different FS

func CopyFile

func CopyFile(srcFs FS, srcFilePath string, destFs FS, destFilePath string) error

CopyFile slow copy file across different FS

Types

type Blob

type Blob interface {
	FS
	Linker
}

type Copier

type Copier interface {
	// Copy src target to dest
	Copy(ctx context.Context, src, dest string) error
}

type FS

type FS = afero.Fs

type File

type File = afero.File

File represents a file in the filesystem.

type FileInfo

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

func NewFileInfo

func NewFileInfo(name string, isDirectory bool, size int64, modTime time.Time) *FileInfo

NewFileInfo create file info which implements os.FileInfo

func (*FileInfo) IsDir

func (f *FileInfo) IsDir() bool

func (*FileInfo) ModTime

func (f *FileInfo) ModTime() time.Time

func (*FileInfo) Mode

func (f *FileInfo) Mode() fs.FileMode

func (*FileInfo) Name

func (f *FileInfo) Name() string

func (*FileInfo) Size

func (f *FileInfo) Size() int64

func (*FileInfo) Sys

func (f *FileInfo) Sys() any

type Initializer

type Initializer interface {
	Init(ctx context.Context) error
	Dispose(ctx context.Context) error
}
type Link struct {
	URL        string         `json:"url"`
	Header     http.Header    `json:"header"` // needed header
	Status     int            // status maybe 200 or 206, etc
	Expiration *time.Duration // url expiration time
}

type LinkOptions

type LinkOptions struct {
	IP     string
	Header http.Header
	Type   string
	Expire *time.Duration
}

type Linker

type Linker interface {
	PreSignedURL(ctx context.Context, name string, args ...LinkOptions) (*Link, error)
	PublicUrl(ctx context.Context, name string) (*Link, error)
	InternalUrl(ctx context.Context, name string, args ...LinkOptions) (*Link, error)
}

type ListOptions

type ListOptions struct {
	// Prefix indicates that only blobs with a key starting with this prefix
	// should be returned.
	Prefix string
	// Delimiter sets the delimiter used to define a hierarchical namespace,
	// like a filesystem with "directories". It is highly recommended that you
	// use "" or "/" as the Delimiter. Other values should work through this API,
	// but service UIs generally assume "/".
	//
	// An empty delimiter means that the bucket is treated as a single flat
	// namespace.
	//
	// A non-empty delimiter means that any result with the delimiter in its key
	// after Prefix is stripped will be returned with ListObject.IsDir = true,
	// ListObject.Key truncated after the delimiter, and zero values for other
	// ListObject fields. These results represent "directories". Multiple results
	// in a "directory" are returned as a single result.
	Delimiter string
}

type Lister

type Lister interface {
	ListPage(ctx context.Context, pageToken []byte, pageSize int, opts *ListOptions) (retval []*fs.FileInfo, nextPageToken []byte, err error)
}

type MountPoint

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

A MountPoint represents a mounted file system.

func (*MountPoint) GetFS

func (mp *MountPoint) GetFS() FS

func (*MountPoint) GetOpenCount

func (mp *MountPoint) GetOpenCount() int32

func (*MountPoint) GetPrefix

func (mp *MountPoint) GetPrefix() string

type Mover

type Mover interface {
	// Move src target to dest
	Move(ctx context.Context, src, dest string) error
}

type OptLinker

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

OptLinker wrap FS as Linker

func NewOptLinker

func NewOptLinker(fs FS, publicAccessUrl url.URL, internalAccessUrl url.URL, tv TokenValidator) *OptLinker

func (*OptLinker) InternalUrl

func (o *OptLinker) InternalUrl(ctx context.Context, name string, args ...LinkOptions) (res *Link, err error)

func (*OptLinker) PreSignedURL

func (o *OptLinker) PreSignedURL(ctx context.Context, name string, args ...LinkOptions) (res *Link, err error)

func (*OptLinker) PublicUrl

func (o *OptLinker) PublicUrl(ctx context.Context, name string) (res *Link, err error)

type TokenValidator

type TokenValidator interface {
	Gen(ctx context.Context, key string, opts ...LinkOptions) (string, error)
	Validate(ctx context.Context, key string, opts ...LinkOptions) (bool, error)
}

type Vfs

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

func New

func New() *Vfs

func (*Vfs) Chmod

func (v *Vfs) Chmod(name string, mode os.FileMode) error

func (*Vfs) Chown

func (v *Vfs) Chown(name string, uid, gid int) error

func (*Vfs) Chtimes

func (v *Vfs) Chtimes(name string, atime time.Time, mtime time.Time) error

func (*Vfs) Create

func (v *Vfs) Create(name string) (File, error)

func (*Vfs) InternalUrl

func (v *Vfs) InternalUrl(ctx context.Context, name string, args ...LinkOptions) (*Link, error)

func (*Vfs) Mkdir

func (v *Vfs) Mkdir(name string, perm os.FileMode) (err error)

func (*Vfs) MkdirAll

func (v *Vfs) MkdirAll(p string, perm os.FileMode) (err error)

func (*Vfs) Mount

func (v *Vfs) Mount(prefix string, fsys FS) error

Mount mounts a filesystem with a provided prefix. Prefix can be any slash-separated path and does not have to represent an existing directory (in this respect it is similar to URL path). Mounted filesystem becomes available to os package.

func (*Vfs) Mounts

func (v *Vfs) Mounts() []*MountPoint

func (*Vfs) Name

func (v *Vfs) Name() string

func (*Vfs) Open

func (v *Vfs) Open(name string) (f File, err error)

func (*Vfs) OpenFile

func (v *Vfs) OpenFile(name string, flag int, perm os.FileMode) (f File, err error)

func (*Vfs) PreSignedURL

func (v *Vfs) PreSignedURL(ctx context.Context, name string, args ...LinkOptions) (*Link, error)

func (*Vfs) PublicUrl

func (v *Vfs) PublicUrl(ctx context.Context, name string) (*Link, error)

func (*Vfs) Remove

func (v *Vfs) Remove(name string) error

func (*Vfs) RemoveAll

func (v *Vfs) RemoveAll(path string) error

func (*Vfs) Rename

func (v *Vfs) Rename(oldname, newname string) error

func (*Vfs) Stat

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

func (*Vfs) Unmount

func (v *Vfs) Unmount(prefix string, fsys FS) error

Unmount unmounts the last mounted filesystem that match fsys and prefix. At least one parameter must be specified (not empty or nil).

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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