filesys

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 26 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 ErrNoFileFound = errors.New("no file found")

ErrNoFileFound is returned when CreateEmbedFSHash finds no files to process

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

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

Functions

func Copy

func Copy(destFS, srcFS filesys_interface.FileSystem) (int, error)

func CreateEmbedFSHash

func CreateEmbedFSHash(f embed.FS, opts ...Option) (string, error)

func DumpTreeView

func DumpTreeView(f fi.FileSystem) string

func DumpTreeViewWithLimits

func DumpTreeViewWithLimits(f fi.FileSystem, maxDepth, maxLines int) string

func Glance

func Glance(localfile any) string

Glance 快速查看一个文件系统或本地目录的概览信息(统计与树形结构) 参数:

  • localfile: 本地目录路径,或一个 FileSystem 对象

返回值:

  • 包含目录统计与树形视图的概览字符串

Example: ``` // 在临时目录创建文件后查看概览,输出应包含统计信息 root = file.Join(os.TempDir(), "yak-filesys-glance") file.MkdirAll(root) file.Save(file.Join(root, "a.txt"), "A")~ summary = filesys.Glance(root) assert str.Contains(summary, "total:"), "Glance output should contain a total summary" file.Remove(root) ```

func NewArchiveFSFromLocal

func NewArchiveFSFromLocal(archivePath string) (fi.FileSystem, error)

NewArchiveFSFromLocal creates a read-only filesystem from a local archive file. Supported archive formats are zip, tar, tar.gz and tgz.

func NewEmbedFS

func NewEmbedFS(fs embed.FS) fi.FileSystem

func Peephole

func Peephole(f fi.FileSystem, opts ...PeepholeConfigOption) error

func Recursive

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

Recursive 递归遍历指定路径下的所有文件和目录,对每个条目按配置的回调进行处理 参数:

  • raw: 起始遍历的根路径
  • opts: 遍历选项(如 filesys.onFileStat、filesys.onDirStat、filesys.dir 等)

返回值:

  • 错误信息

Example: ``` // 在临时目录创建两个文件,递归统计文件数量 root = file.Join(os.TempDir(), "yak-filesys-recursive") file.MkdirAll(root) file.Save(file.Join(root, "a.txt"), "A")~ file.Save(file.Join(root, "b.txt"), "B")~ count = 0 filesys.Recursive(root, filesys.onFileStat((name, info) => { count++ }))~ assert count == 2, "Recursive should visit both files" file.Remove(root) ```

func SerializeFileSystemToGzipBytes

func SerializeFileSystemToGzipBytes(fsys fi.FileSystem, opts ...GzipSerializeOption) ([]byte, error)

SerializeFileSystemToGzipBytes serializes a filesystem into tar.gz bytes.

func SimpleRecursive

func SimpleRecursive(opts ...Option) error

func SplitWithSeparator

func SplitWithSeparator(path string, sep rune) (string, string)

func TreeView

func TreeView(f fi.FileSystem)

func WithUnifiedFsExtMap

func WithUnifiedFsExtMap(extReal, extVirtual string) func(config *UnifiedFSConfig)

func WithUnifiedFsSeparator

func WithUnifiedFsSeparator(sep rune) func(config *UnifiedFSConfig)

Types

type Config

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

func NewConfig

func NewConfig() *Config

func (*Config) Stop

func (c *Config) Stop()

type DirStat

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 {
	Id           string
	CreateEvents []Event
	DeleteEvents []Event
	ChangeEvents []Event
}

func CompareFileTree

func CompareFileTree(prev, 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

type FileStat func(string, fs.FileInfo) error

type GzipFS

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

GzipFS is a runtime tar.gz-backed filesystem materialized into a VirtualFS. It is primarily used to persist and restore small embedded file trees.

func NewGzipFSFromBytes

func NewGzipFSFromBytes(data []byte) (*GzipFS, error)

NewGzipFSFromBytes restores a tar.gz-encoded filesystem into a VirtualFS-backed FS.

type GzipSerializeOption

type GzipSerializeOption func(*gzipSerializeConfig)

func WithGzipFSExcludePaths

func WithGzipFSExcludePaths(paths ...string) GzipSerializeOption

WithGzipFSExcludePaths excludes specific paths from serialized tar.gz output.

type HookAfterFunc

type HookAfterFunc func(ctx *ReadHookContext, data []byte) ([]byte, error)

type HookBeforeFunc

type HookBeforeFunc func(ctx *ReadHookContext) error

type HookFS

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

func NewHookFS

func NewHookFS(underlying fi.FileSystem) *HookFS

NewHookFS 创建 HookFS。

func (*HookFS) AddReadHook

func (f *HookFS) AddReadHook(hook *ReadHook)

AddReadHook 注册一个 read hook。

func (*HookFS) Base

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

func (*HookFS) Delete

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

func (*HookFS) Exists

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

func (*HookFS) Ext

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

func (*HookFS) ExtraInfo

func (f *HookFS) ExtraInfo(path string) map[string]any

func (*HookFS) GetSeparators

func (f *HookFS) GetSeparators() rune

func (*HookFS) Getwd

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

func (*HookFS) IsAbs

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

func (*HookFS) Join

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

func (*HookFS) MkdirAll

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

func (*HookFS) Open

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

func (*HookFS) OpenFile

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

func (*HookFS) PathSplit

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

func (*HookFS) ReadDir

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

func (*HookFS) ReadFile

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

func (*HookFS) Rel

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

func (*HookFS) Rename

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

func (*HookFS) Root

func (f *HookFS) Root() string

func (*HookFS) SetEnabled

func (f *HookFS) SetEnabled(enabled bool)

SetEnabled 控制是否启用 hook 能力。

func (*HookFS) Stat

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

func (*HookFS) String

func (f *HookFS) String() string

func (*HookFS) WriteFile

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

type HookMatcher

type HookMatcher interface {
	Match(name string) bool
}

func CustomMatcher

func CustomMatcher(fn func(string) bool) HookMatcher

CustomMatcher 允许外部直接提供函数。

func MatchAll

func MatchAll() HookMatcher

MatchAll 返回一个总是匹配的 matcher。

func SuffixMatcher

func SuffixMatcher(suffixes ...string) HookMatcher

SuffixMatcher 根据后缀匹配文件名,不区分大小写。

type HookMatcherFunc

type HookMatcherFunc func(name string) bool

func (HookMatcherFunc) Match

func (f HookMatcherFunc) Match(name string) bool

type LocalFs

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

local FileSystem

func NewLocalFs

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

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

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

func (*LocalFs) MkdirAll

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

func (*LocalFs) Open

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

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

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

func (*LocalFs) String

func (f *LocalFs) String() string

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 WithContext

func WithContext(ctx context.Context) Option

func WithDir

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

dir 为匹配指定 glob 目录的子树设置一组单独的遍历选项 参数:

  • globDir: 目录匹配的 glob 模式
  • opts: 对匹配到的子目录生效的遍历选项

返回值:

  • 一个遍历配置选项

Example: ``` filesys.Recursive("testdata", filesys.dir("cc", filesys.onFileStat((name, info) => {})))~ ```

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 WithExcludeExts

func WithExcludeExts(exts ...string) Option

WithExcludeExts sets file extensions to exclude (files with these extensions will be skipped) The filtering is handled in Recursive function before calling onFileStat. Example: WithExcludeExts(".tmp", ".bak")

func WithFileLimit

func WithFileLimit(limit int) Option

func WithFileStat

func WithFileStat(f FileStat) Option

func WithFileSystem

func WithFileSystem(f fi.FileSystem) Option

func WithIncludeExts

func WithIncludeExts(exts ...string) Option

WithIncludeExts sets file extensions to include (only files with these extensions will be processed) The filtering is handled in Recursive function before calling onFileStat. Example: WithIncludeExts(".yak", ".fs")

func WithOnStart

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

func WithRecursiveDirectory

func WithRecursiveDirectory(b bool) Option

func WithStat

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

type PeepholeConfig

type PeepholeConfig struct {
	// peephole handler
	Size int

	Callback func(count, total int, f fi.FileSystem)
	// contains filtered or unexported fields
}

func (*PeepholeConfig) CallbackFS

func (c *PeepholeConfig) CallbackFS(f fi.FileSystem, triggers *utils.SafeMap[*PeepholeTrigger])

type PeepholeConfigOption

type PeepholeConfigOption func(*PeepholeConfig) error

func WithPeepholeCallback

func WithPeepholeCallback(i func(int, int, fi.FileSystem)) PeepholeConfigOption

func WithPeepholeContext

func WithPeepholeContext(ctx context.Context) PeepholeConfigOption

func WithPeepholeSize

func WithPeepholeSize(i int) PeepholeConfigOption

type PeepholeTrigger

type PeepholeTrigger struct {
	Path  string
	Infos []fs.FileInfo
}

type ReadHook

type ReadHook struct {
	Matcher    HookMatcher
	BeforeRead HookBeforeFunc
	AfterRead  HookAfterFunc
}

type ReadHookContext

type ReadHookContext struct {
	Name       string
	FS         fi.FileSystem
	Underlying fi.FileSystem
}

type RelLocalFs

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

func CopyToRefLocal

func CopyToRefLocal(srcFs filesys_interface.FileSystem, dest string) (*RelLocalFs, error)

CopyToRefLocal 把一个源文件系统的全部内容拷贝到指定的本地目录,并返回指向该目录的文件系统对象 参数:

  • srcFs: 源文件系统对象
  • dest: 目标本地目录路径(不存在时会自动创建)

返回值:

  • 指向目标本地目录的文件系统对象
  • 错误信息

Example: ``` // 将一个内存 zip 文件系统拷贝到本地目录 zfs = filesys.NewZipFSFromLocal("/tmp/abc.zip")~ localFs = filesys.CopyToRefLocal(zfs, "/tmp/abc_extracted")~ ```

func CopyToTemporary

func CopyToTemporary(srcFs filesys_interface.FileSystem) *RelLocalFs

CopyToTemporary 把一个源文件系统的全部内容拷贝到一个新建的临时目录,并返回指向该临时目录的文件系统对象 参数:

  • srcFs: 源文件系统对象

返回值:

  • 指向新建临时目录的文件系统对象

Example: ``` // 将一个内存 zip 文件系统拷贝到临时目录 zfs = filesys.NewZipFSFromLocal("/tmp/abc.zip")~ tmpFs = filesys.CopyToTemporary(zfs) ```

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) Root

func (f *RelLocalFs) Root() string

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 UnifiedDirEntry

type UnifiedDirEntry struct {
	fs.DirEntry
	// contains filtered or unexported fields
}

func (*UnifiedDirEntry) Info

func (e *UnifiedDirEntry) Info() (fs.FileInfo, error)

func (*UnifiedDirEntry) Name

func (e *UnifiedDirEntry) Name() string

type UnifiedFS

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

func NewUnifiedFS

func NewUnifiedFS(fs fi.FileSystem, opts ...UnifiedFsOption) *UnifiedFS

func (*UnifiedFS) Base

func (u *UnifiedFS) Base(name string) string

func (*UnifiedFS) Delete

func (u *UnifiedFS) Delete(name string) error

func (*UnifiedFS) Exists

func (u *UnifiedFS) Exists(name string) (bool, error)

func (*UnifiedFS) Ext

func (u *UnifiedFS) Ext(name string) string

func (*UnifiedFS) ExtraInfo

func (u *UnifiedFS) ExtraInfo(s string) map[string]any

func (*UnifiedFS) GetFileSystem

func (u *UnifiedFS) GetFileSystem() fi.FileSystem

func (*UnifiedFS) GetSeparators

func (u *UnifiedFS) GetSeparators() rune

func (*UnifiedFS) Getwd

func (u *UnifiedFS) Getwd() (string, error)

func (*UnifiedFS) IsAbs

func (u *UnifiedFS) IsAbs(name string) bool

func (*UnifiedFS) Join

func (u *UnifiedFS) Join(elem ...string) string

func (*UnifiedFS) MkdirAll

func (u *UnifiedFS) MkdirAll(name string, perm os.FileMode) error

func (*UnifiedFS) Open

func (u *UnifiedFS) Open(name string) (fs.File, error)

func (*UnifiedFS) OpenFile

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

func (*UnifiedFS) PathSplit

func (u *UnifiedFS) PathSplit(name string) (string, string)

func (*UnifiedFS) ReadDir

func (u *UnifiedFS) ReadDir(name string) ([]fs.DirEntry, error)

func (*UnifiedFS) ReadFile

func (u *UnifiedFS) ReadFile(name string) ([]byte, error)

func (*UnifiedFS) Rel

func (u *UnifiedFS) Rel(s string, s2 string) (string, error)

func (*UnifiedFS) Rename

func (u *UnifiedFS) Rename(old string, new string) error

func (*UnifiedFS) Stat

func (u *UnifiedFS) Stat(name string) (fs.FileInfo, error)

func (*UnifiedFS) String

func (f *UnifiedFS) String() string

func (*UnifiedFS) WriteFile

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

type UnifiedFSConfig

type UnifiedFSConfig struct {
	Separator rune
	// contains filtered or unexported fields
}

type UnifiedFile

type UnifiedFile struct {
	fs.File
	// contains filtered or unexported fields
}

func (*UnifiedFile) Name

func (f *UnifiedFile) Name() string

func (*UnifiedFile) Stat

func (f *UnifiedFile) Stat() (fs.FileInfo, error)

type UnifiedFileInfo

type UnifiedFileInfo struct {
	fs.FileInfo
	// contains filtered or unexported fields
}

func (*UnifiedFileInfo) IsDir

func (i *UnifiedFileInfo) IsDir() bool

func (*UnifiedFileInfo) Name

func (i *UnifiedFileInfo) Name() string

type UnifiedFsOption

type UnifiedFsOption func(config *UnifiedFSConfig)

type VirtualFS

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

func NewTarFSFromBytes

func NewTarFSFromBytes(data []byte) (*VirtualFS, error)

NewTarFSFromBytes restores a tar-encoded filesystem into a VirtualFS-backed FS.

func NewVirtualFs

func NewVirtualFs() *VirtualFS

func (*VirtualFS) AddDir

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

func (*VirtualFS) AddFile

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

func (f *VirtualFS) GetLocalFSPath() string

func (*VirtualFS) GetSeparators

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

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

func (*VirtualFS) MkdirAll

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

func (*VirtualFS) Open

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

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

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

func (*VirtualFS) Rename

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

func (*VirtualFS) Stat

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

func (*VirtualFS) String

func (f *VirtualFS) String() string

func (*VirtualFS) WriteFile

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

type VirtualFile

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

func NewVirtualFile

func NewVirtualFile(name string, content string) *VirtualFile

func NewVirtualFileDirectory

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

func (*VirtualFile) Close

func (vf *VirtualFile) Close() error

func (*VirtualFile) FS

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

func (*VirtualFile) Read

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

func (*VirtualFile) Stat

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

type VirtualFileInfo

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

func NewVirtualFileInfo

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

func (*VirtualFileInfo) Info

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

func (*VirtualFileInfo) IsDir

func (vi *VirtualFileInfo) IsDir() bool

func (*VirtualFileInfo) ModTime

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

func (*VirtualFileInfo) Mode

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

func (*VirtualFileInfo) Name

func (vi *VirtualFileInfo) Name() string

func (*VirtualFileInfo) Size

func (vi *VirtualFileInfo) Size() int64

func (*VirtualFileInfo) Sys

func (vi *VirtualFileInfo) Sys() any

func (*VirtualFileInfo) Type

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

type WatchPathOption

type WatchPathOption func(*watchPathConfig)

func WithPollInterval

func WithPollInterval(interval time.Duration) WatchPathOption

type YakFileMonitor

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

	FileTreeMutex sync.Mutex
	FileTree      *FileNode

	WatchPatch   string
	PollInterval time.Duration

	Ctx        context.Context
	CancelFunc context.CancelFunc
}

func WatchPath

func WatchPath(ctx context.Context, path string, eventHandler MonitorEventHandler, opts ...WatchPathOption) (*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 NewZipFSFromLocalWithOptions

func NewZipFSFromLocalWithOptions(i string, opts ...ZipFSOption) (*ZipFS, error)

NewZipFSFromLocalWithOptions 从本地文件构造带密码 ZipFS 关键词: ZipFS 密码构造, NewZipFSFromLocalWithOptions

func NewZipFSFromString

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

func NewZipFSFromStringWithOptions

func NewZipFSFromStringWithOptions(i string, opts ...ZipFSOption) (*ZipFS, error)

NewZipFSFromStringWithOptions 从字符串/字节构造带密码 ZipFS 关键词: ZipFS 密码构造, NewZipFSFromStringWithOptions

func NewZipFSRaw

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

func NewZipFSRawWithCloser

func NewZipFSRawWithCloser(i io.ReaderAt, size int64, closer io.Closer) (*ZipFS, error)

NewZipFSRawWithCloser 创建一个 ZipFS,并保存一个可选的 closer 用于关闭文件句柄

func NewZipFSRawWithCloserAndOptions

func NewZipFSRawWithCloserAndOptions(i io.ReaderAt, size int64, closer io.Closer, opts ...ZipFSOption) (*ZipFS, error)

NewZipFSRawWithCloserAndOptions 同 NewZipFSRawWithCloser,但接受 ZipFSOption 关键词: ZipFS 密码构造, NewZipFSRawWithCloserAndOptions

func NewZipFSRawWithOptions

func NewZipFSRawWithOptions(i io.ReaderAt, size int64, opts ...ZipFSOption) (*ZipFS, error)

NewZipFSRawWithOptions 创建带选项(含密码)的 ZipFS 关键词: ZipFS 密码构造, NewZipFSRawWithOptions

func (*ZipFS) Base

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

func (*ZipFS) Clean

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

func (*ZipFS) Close

func (z *ZipFS) Close() error

Close 关闭 ZipFS 持有的文件句柄(如果存在) 这对于在 Windows 上释放文件锁定很重要

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) SetPassword

func (z *ZipFS) SetPassword(password string) *ZipFS

SetPassword 后置设置 ZipFS 解密密码 关键词: ZipFS 密码运行时设置

func (*ZipFS) Stat

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

func (*ZipFS) String

func (f *ZipFS) String() string

func (*ZipFS) WriteFile

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

type ZipFSOption

type ZipFSOption func(*zipFSConfig)

ZipFSOption 用于 NewZipFS*WithOptions 的可选参数 关键词: ZipFS 选项, ZipFS 密码

func WithZipFSPassword

func WithZipFSPassword(password string) ZipFSOption

WithZipFSPassword 设置加密 zip 的解密密码 关键词: ZipFS 密码, 加密 zip 文件系统

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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