filesys

package
v1.3.6-beta3 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FsMonitorCreate = "create" // dir
	FsMonitorWrite  = "write"
	FsMonitorRename = "rename"
	FsMonitorRemove = "remove"
	FsMonitorChmod  = "chmod"
	FsMonitorChange = "change"
	FsMonitorTouch  = "touch"
	FsMonitorDelete = "delete"
)

Variables

View Source
var Exports = map[string]any{
	"Recursive": Recursive,

	"onReady":    withYaklangOnStart,
	"onStat":     withYaklangStat,
	"onFileStat": withYaklangFileStat,
	"onDirStat":  withYaklangDirStat,
	"dir":        WithDir,
}
View Source
var SkipAll = errors.New("skip all")
View Source
var SkipDir = errors.New("skip dir")

Functions

func NewEmbedFS added in v1.3.3

func NewEmbedFS(fs embed.FS) fi.FileSystem

func Recursive

func Recursive(raw string, opts ...Option) error

Recursive recursively walk through the file system raw: the root path opts: options return: error

Example: ``` err := filesys.Recursive( //

"testdata",
filesys.dir(["cc", "dd"], filesys.onFileStat((name, info) => {})),

) ```

Types

type Config

type Config struct {
	RecursiveDirectory bool
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig() *Config

type DirStat added in v1.3.3

type DirStat func(string, fs.FileInfo) error

type Event

type Event struct {
	Path  string
	Op    string
	IsDir bool
}

type MonitorErrorsHandler func(error)

type EventSet

type EventSet struct {
	CreateEvents []Event
	DeleteEvents []Event
	ChangeEvents []Event
}

func CompareFileTree

func CompareFileTree(perv, current *FileNode) *EventSet

func (EventSet) IsEmpty

func (set EventSet) IsEmpty() bool

type FileNode

type FileNode struct {
	Info     os.FileInfo
	Path     string
	Children map[string]*FileNode
	Parent   *FileNode
	IsRoot   bool
}

func GetCurrentFileTree

func GetCurrentFileTree(path string) (*FileNode, error)

func (*FileNode) IsDir

func (n *FileNode) IsDir() bool

type FileStat added in v1.3.3

type FileStat func(string, fs.FileInfo) error

type LocalFs added in v1.3.3

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

local FileSystem

func NewLocalFs added in v1.3.3

func NewLocalFs() *LocalFs

func (*LocalFs) Base

func (f *LocalFs) Base(p string) string

func (*LocalFs) Delete

func (f *LocalFs) Delete(name string) error

func (*LocalFs) Exists

func (f *LocalFs) Exists(path string) (bool, error)

func (*LocalFs) Ext

func (f *LocalFs) Ext(s string) string

func (*LocalFs) ExtraInfo

func (f *LocalFs) ExtraInfo(string) map[string]any

func (*LocalFs) GetSeparators added in v1.3.3

func (f *LocalFs) GetSeparators() rune

func (*LocalFs) Getwd

func (f *LocalFs) Getwd() (string, error)

func (*LocalFs) IsAbs

func (f *LocalFs) IsAbs(name string) bool

func (*LocalFs) Join added in v1.3.3

func (f *LocalFs) Join(paths ...string) string

func (*LocalFs) MkdirAll

func (f *LocalFs) MkdirAll(name string, perm os.FileMode) error

func (*LocalFs) Open added in v1.3.3

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

func (*LocalFs) OpenFile

func (f *LocalFs) OpenFile(name string, flag int, perm os.FileMode) (fs.File, error)

func (*LocalFs) PathSplit

func (f *LocalFs) PathSplit(s string) (string, string)

func (*LocalFs) ReadDir added in v1.3.3

func (f *LocalFs) ReadDir(dirname string) ([]fs.DirEntry, error)

func (*LocalFs) ReadFile

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

func (*LocalFs) Rel

func (f *LocalFs) Rel(base string, target string) (string, error)

func (*LocalFs) Rename

func (f *LocalFs) Rename(old string, new string) error

func (*LocalFs) Stat added in v1.3.3

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

func (*LocalFs) Throw

func (f *LocalFs) Throw(filenames ...string) error

fallback to Delete on unix

func (*LocalFs) WriteFile

func (f *LocalFs) WriteFile(name string, data []byte, perm os.FileMode) error

type MonitorEventHandler

type MonitorEventHandler func(events *EventSet)

type Option

type Option func(*Config)

func WithDir

func WithDir(globDir string, opts ...Option) Option

func WithDirStat

func WithDirStat(f DirStat) Option

func WithDirWalkEnd

func WithDirWalkEnd(handle func(path string) error) Option

func WithEmbedFS

func WithEmbedFS(f embed.FS) Option

func WithFileStat

func WithFileStat(f FileStat) Option

func WithFileSystem

func WithFileSystem(f fi.FileSystem) Option

func WithOnStart

func WithOnStart(f func(basename string, isDir bool) error) Option

func WithRecursiveDirectory added in v1.3.3

func WithRecursiveDirectory(b bool) Option

func WithStat

func WithStat(f func(isDir bool, pathname string, info os.FileInfo) error) Option

type RelLocalFs

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

func NewRelLocalFs

func NewRelLocalFs(rel string) *RelLocalFs

func (*RelLocalFs) Base

func (f *RelLocalFs) Base(p string) string

func (*RelLocalFs) Delete

func (f *RelLocalFs) Delete(name string) error

func (*RelLocalFs) Exists

func (f *RelLocalFs) Exists(path string) (bool, error)

func (*RelLocalFs) Ext

func (f *RelLocalFs) Ext(s string) string

func (*RelLocalFs) ExtraInfo

func (f *RelLocalFs) ExtraInfo(string) map[string]any

func (*RelLocalFs) GetSeparators

func (f *RelLocalFs) GetSeparators() rune

func (*RelLocalFs) Getwd

func (f *RelLocalFs) Getwd() (string, error)

func (*RelLocalFs) IsAbs

func (f *RelLocalFs) IsAbs(name string) bool

func (*RelLocalFs) Join

func (f *RelLocalFs) Join(paths ...string) string

func (*RelLocalFs) MkdirAll

func (f *RelLocalFs) MkdirAll(name string, perm os.FileMode) error

func (*RelLocalFs) Open

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

func (*RelLocalFs) OpenFile

func (f *RelLocalFs) OpenFile(name string, flag int, perm os.FileMode) (fs.File, error)

func (*RelLocalFs) PathSplit

func (f *RelLocalFs) PathSplit(s string) (string, string)

func (*RelLocalFs) ReadDir

func (f *RelLocalFs) ReadDir(dirname string) ([]fs.DirEntry, error)

func (*RelLocalFs) ReadFile

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

func (*RelLocalFs) Rel

func (f *RelLocalFs) Rel(base string, target string) (string, error)

func (*RelLocalFs) Rename

func (f *RelLocalFs) Rename(old string, new string) error

func (*RelLocalFs) Stat

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

func (*RelLocalFs) String

func (f *RelLocalFs) String() string

func (*RelLocalFs) WriteFile

func (f *RelLocalFs) WriteFile(name string, data []byte, perm os.FileMode) error

type VirtualFS added in v1.3.3

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

func NewVirtualFs added in v1.3.3

func NewVirtualFs() *VirtualFS

func (*VirtualFS) AddDir added in v1.3.3

func (f *VirtualFS) AddDir(dirName string) *VirtualFile

func (*VirtualFS) AddFile added in v1.3.3

func (f *VirtualFS) AddFile(name, content string)

func (*VirtualFS) Base

func (f *VirtualFS) Base(s string) string

func (*VirtualFS) Delete

func (f *VirtualFS) Delete(path string) error

func (*VirtualFS) Exists

func (f *VirtualFS) Exists(path string) (bool, error)

func (*VirtualFS) Ext

func (f *VirtualFS) Ext(s string) string

func (*VirtualFS) ExtraInfo

func (f *VirtualFS) ExtraInfo(string) map[string]any

func (*VirtualFS) GetLocalFSPath added in v1.3.3

func (f *VirtualFS) GetLocalFSPath() string

func (*VirtualFS) GetSeparators added in v1.3.3

func (f *VirtualFS) GetSeparators() rune

func (*VirtualFS) Getwd

func (f *VirtualFS) Getwd() (string, error)

func (*VirtualFS) IsAbs

func (f *VirtualFS) IsAbs(name string) bool

func (*VirtualFS) Join added in v1.3.3

func (f *VirtualFS) Join(name ...string) string

func (*VirtualFS) MkdirAll

func (f *VirtualFS) MkdirAll(path string, mode os.FileMode) error

func (*VirtualFS) Open added in v1.3.3

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

func (*VirtualFS) OpenFile

func (f *VirtualFS) OpenFile(name string, flag int, perm os.FileMode) (fs.File, error)

func (*VirtualFS) PathSplit

func (f *VirtualFS) PathSplit(s string) (string, string)

func (*VirtualFS) ReadDir added in v1.3.3

func (f *VirtualFS) ReadDir(name string) ([]fs.DirEntry, error)

func (*VirtualFS) ReadFile

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

func (*VirtualFS) Rel

func (f *VirtualFS) Rel(string, string) (string, error)

func (*VirtualFS) RemoveFileOrDir added in v1.3.3

func (f *VirtualFS) RemoveFileOrDir(name string) error

func (*VirtualFS) Rename

func (f *VirtualFS) Rename(string, string) error

func (*VirtualFS) Stat added in v1.3.3

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

func (*VirtualFS) WriteFile

func (f *VirtualFS) WriteFile(name string, data []byte, mode os.FileMode) error

type VirtualFile added in v1.3.3

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

func NewVirtualFile added in v1.3.3

func NewVirtualFile(name string, content string) *VirtualFile

func NewVirtualFileDirectory added in v1.3.3

func NewVirtualFileDirectory(dirName string, dir *VirtualFS) *VirtualFile

func (*VirtualFile) Close added in v1.3.3

func (vf *VirtualFile) Close() error

func (*VirtualFile) FS

func (f *VirtualFile) FS() fi.FileSystem

func (*VirtualFile) Read added in v1.3.3

func (vf *VirtualFile) Read(p []byte) (int, error)

func (*VirtualFile) Stat added in v1.3.3

func (vf *VirtualFile) Stat() (fs.FileInfo, error)

type VirtualFileInfo added in v1.3.3

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

func NewVirtualFileInfo added in v1.3.3

func NewVirtualFileInfo(name string, size int64, isDir bool) *VirtualFileInfo

func (*VirtualFileInfo) Info added in v1.3.3

func (vi *VirtualFileInfo) Info() (fs.FileInfo, error)

func (*VirtualFileInfo) IsDir added in v1.3.3

func (vi *VirtualFileInfo) IsDir() bool

func (*VirtualFileInfo) ModTime added in v1.3.3

func (vi *VirtualFileInfo) ModTime() time.Time

func (*VirtualFileInfo) Mode added in v1.3.3

func (vi *VirtualFileInfo) Mode() os.FileMode

func (*VirtualFileInfo) Name added in v1.3.3

func (vi *VirtualFileInfo) Name() string

func (*VirtualFileInfo) Size added in v1.3.3

func (vi *VirtualFileInfo) Size() int64

func (*VirtualFileInfo) Sys added in v1.3.3

func (vi *VirtualFileInfo) Sys() any

func (*VirtualFileInfo) Type added in v1.3.3

func (vi *VirtualFileInfo) Type() fs.FileMode

type YakFileMonitor

type YakFileMonitor struct {
	Events          chan *EventSet
	RecursiveFinish chan struct{} // recursive finish

	FileTreeMutex sync.Mutex
	FileTree      *FileNode

	WatchPatch string

	Ctx        context.Context
	CancelFunc context.CancelFunc
}

func WatchPath

func WatchPath(ctx context.Context, path string, eventHandler MonitorEventHandler) (*YakFileMonitor, error)

func (*YakFileMonitor) SetFileTree

func (m *YakFileMonitor) SetFileTree(fileTree *FileNode)

func (*YakFileMonitor) UpdateFileTree

func (m *YakFileMonitor) UpdateFileTree() error

type ZipDirEntry

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

func (*ZipDirEntry) Info

func (z *ZipDirEntry) Info() (fs.FileInfo, error)

func (*ZipDirEntry) IsDir

func (z *ZipDirEntry) IsDir() bool

func (*ZipDirEntry) Name

func (z *ZipDirEntry) Name() string

func (*ZipDirEntry) Type

func (z *ZipDirEntry) Type() fs.FileMode

type ZipFS

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

func NewZipFSFromLocal

func NewZipFSFromLocal(i string) (*ZipFS, error)

func NewZipFSFromString

func NewZipFSFromString(i string) (*ZipFS, error)

func NewZipFSRaw

func NewZipFSRaw(i io.ReaderAt, size int64) (*ZipFS, error)

func (*ZipFS) Base

func (f *ZipFS) Base(p string) string

func (*ZipFS) Clean

func (z *ZipFS) Clean(name string) string

func (*ZipFS) Delete

func (z *ZipFS) Delete(s string) error

func (*ZipFS) Exists

func (z *ZipFS) Exists(s string) (bool, error)

func (*ZipFS) Ext

func (z *ZipFS) Ext(i string) string

func (*ZipFS) ExtraInfo

func (f *ZipFS) ExtraInfo(string) map[string]any

func (*ZipFS) GetSeparators

func (z *ZipFS) GetSeparators() rune

func (*ZipFS) Getwd

func (z *ZipFS) Getwd() (string, error)

func (*ZipFS) IsAbs

func (z *ZipFS) IsAbs(s string) bool

func (*ZipFS) Join

func (z *ZipFS) Join(name ...string) string

func (*ZipFS) MkdirAll

func (z *ZipFS) MkdirAll(s string, mode os.FileMode) error

func (*ZipFS) Open

func (z *ZipFS) Open(name string) (fs.File, error)

func (*ZipFS) OpenFile

func (z *ZipFS) OpenFile(name string, flag int, perm os.FileMode) (fs.File, error)

func (*ZipFS) PathSplit

func (z *ZipFS) PathSplit(s string) (string, string)

func (*ZipFS) ReadDir

func (z *ZipFS) ReadDir(name string) ([]fs.DirEntry, error)

func (*ZipFS) ReadFile

func (z *ZipFS) ReadFile(name string) ([]byte, error)

func (*ZipFS) Rel

func (z *ZipFS) Rel(s string, s2 string) (string, error)

Rel is calc relative path

func (*ZipFS) Rename

func (z *ZipFS) Rename(s string, s2 string) error

func (*ZipFS) Stat

func (z *ZipFS) Stat(name string) (fs.FileInfo, error)

func (*ZipFS) WriteFile

func (z *ZipFS) WriteFile(s string, bytes []byte, mode os.FileMode) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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