fs

package
v0.0.0-...-75ec8e3 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFile

func CopyFile(src, dst string) error

Helper function to copy a file

Types

type CachedFS

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

CachedFS is a filesystem implementation with directory listing cache

func NewCachedFS

func NewCachedFS(baseDir string, cacheTTL time.Duration, maxEntries int) *CachedFS

NewCachedFS creates a new cached filesystem with fsnotify

func (*CachedFS) ClearCache

func (cfs *CachedFS) ClearCache()

ClearCache removes all entries from cache

func (*CachedFS) Close

func (cfs *CachedFS) Close() error

Close closes the filesystem watcher

func (*CachedFS) Delete

func (cfs *CachedFS) Delete(ctx context.Context, path string) error

func (*CachedFS) DeleteAll

func (cfs *CachedFS) DeleteAll(ctx context.Context, path string) error

func (*CachedFS) Exists

func (cfs *CachedFS) Exists(ctx context.Context, path string) (bool, error)

func (*CachedFS) InvalidateDirCache

func (cfs *CachedFS) InvalidateDirCache(path string)

InvalidateDirCache removes a directory from cache

func (*CachedFS) ListDir

func (cfs *CachedFS) ListDir(ctx context.Context, path string) ([]*FileInfo, error)

func (*CachedFS) MkdirAll

func (cfs *CachedFS) MkdirAll(ctx context.Context, path string, perm os.FileMode) error

func (*CachedFS) Move

func (cfs *CachedFS) Move(ctx context.Context, src, dst string) error

func (*CachedFS) ReadFile

func (cfs *CachedFS) ReadFile(ctx context.Context, path string) ([]byte, error)

func (*CachedFS) ReadFileLines

func (cfs *CachedFS) ReadFileLines(ctx context.Context, path string, from, to int) ([]string, error)

func (*CachedFS) Stat

func (cfs *CachedFS) Stat(ctx context.Context, path string) (*FileInfo, error)

func (*CachedFS) WriteFile

func (cfs *CachedFS) WriteFile(ctx context.Context, path string, data []byte) error

type FileInfo

type FileInfo struct {
	Path    string
	Size    int64
	ModTime time.Time
	IsDir   bool
}

FileInfo represents file metadata

type FileSystem

type FileSystem interface {
	// ReadFile reads the entire file
	ReadFile(ctx context.Context, path string) ([]byte, error)
	// ReadFileLines reads specific lines from a file
	ReadFileLines(ctx context.Context, path string, from, to int) ([]string, error)
	// WriteFile writes data to a file
	WriteFile(ctx context.Context, path string, data []byte) error
	// Stat returns file information
	Stat(ctx context.Context, path string) (*FileInfo, error)
	// ListDir lists directory contents
	ListDir(ctx context.Context, path string) ([]*FileInfo, error)
	// Exists checks if a file exists
	Exists(ctx context.Context, path string) (bool, error)
	// Delete removes a file or empty directory
	Delete(ctx context.Context, path string) error
	// DeleteAll removes a directory and all its contents recursively
	DeleteAll(ctx context.Context, path string) error
	// MkdirAll creates a directory and all parent directories
	MkdirAll(ctx context.Context, path string, perm os.FileMode) error
	// Move renames or moves a file or directory to a new path
	Move(ctx context.Context, src, dst string) error
}

FileSystem is an abstraction over filesystem operations

type MockFS

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

MockFS is a mock filesystem for testing

func NewMockFS

func NewMockFS() *MockFS

func (*MockFS) Delete

func (mfs *MockFS) Delete(ctx context.Context, path string) error

func (*MockFS) DeleteAll

func (mfs *MockFS) DeleteAll(ctx context.Context, path string) error

func (*MockFS) Exists

func (mfs *MockFS) Exists(ctx context.Context, path string) (bool, error)

func (*MockFS) ListDir

func (mfs *MockFS) ListDir(ctx context.Context, path string) ([]*FileInfo, error)

func (*MockFS) MkdirAll

func (mfs *MockFS) MkdirAll(ctx context.Context, path string, perm os.FileMode) error

func (*MockFS) Move

func (mfs *MockFS) Move(ctx context.Context, src, dst string) error

func (*MockFS) ReadFile

func (mfs *MockFS) ReadFile(ctx context.Context, path string) ([]byte, error)

func (*MockFS) ReadFileLines

func (mfs *MockFS) ReadFileLines(ctx context.Context, path string, from, to int) ([]string, error)

func (*MockFS) Stat

func (mfs *MockFS) Stat(ctx context.Context, path string) (*FileInfo, error)

func (*MockFS) WriteFile

func (mfs *MockFS) WriteFile(ctx context.Context, path string, data []byte) error

Jump to

Keyboard shortcuts

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