vfs

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Maximum size for inline content (5MB)
	MAX_INLINE_SIZE = 5 * 1024 * 1024
	// Maximum size for base64 encoding (1MB)
	MAX_BASE64_SIZE = 1 * 1024 * 1024
	// Maximum number of search results to return (prevent excessive output)
	MAX_SEARCH_RESULTS = 1000
	// Maximum file size in bytes to search within (10MB)
	MAX_SEARCHABLE_SIZE = 10 * 1024 * 1024
)

Variables

This section is empty.

Functions

func DataURL added in v0.1.3

func DataURL(mime string, raw []byte) string

https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/data data:[<media-type>][;base64],<data>

func DetectMimeType added in v0.0.9

func DetectMimeType(path string) string

DetectMimeType tries to determine the MIME type of a file

func FormatContentWithLineNumbers added in v0.0.9

func FormatContentWithLineNumbers(content string, startLine int) string

FormatContentWithLineNumbers formats content with line numbers (cat -n style).

func FormatLinesWithLineNumbers added in v0.0.9

func FormatLinesWithLineNumbers(lines []string, startLine int) string

func IsImageFile added in v0.0.9

func IsImageFile(mimeType string) bool

IsImageFile determines if a file is an image based on MIME type

func IsTextFile added in v0.0.9

func IsTextFile(mimeType string) bool

IsTextFile determines if a file is likely a text file based on MIME type

func PathToResourceURI added in v0.1.4

func PathToResourceURI(path string) string

PathToResourceURI converts a file path to a resource URI

func ReadLines added in v0.1.0

func ReadLines(reader io.Reader, number bool, offset int, limit int) (string, error)

Read and format content with line numbers

func Search(path string, o *SearchOptions) (string, error)

Types

type EditOptions added in v0.0.8

type EditOptions struct {
	Find           string
	Replace        string
	AllOccurrences bool
	UseRegex       bool
}

type FileInfo

type FileInfo struct {
	Filename string `json:"filename"`

	IsDirectory bool `json:"isDirectory"`
	IsFile      bool `json:"isFile"`
	IsLink      bool `json:"isLink"`

	Permissions string `json:"permissions"`

	Length   int64     `json:"size"`
	Created  time.Time `json:"created"`
	Modified time.Time `json:"modified"`
	Accessed time.Time `json:"accessed"`

	Mime string `json:"mime"`

	// original info for local fs
	Info fs.FileInfo `json:"-"`
}

func (*FileInfo) IsDir

func (r *FileInfo) IsDir() bool

abbreviation for Mode().IsDir()

func (*FileInfo) ModTime

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

modification time

func (*FileInfo) Mode

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

file mode bits

func (*FileInfo) Name

func (r *FileInfo) Name() string

base name of the file

func (*FileInfo) Size

func (r *FileInfo) Size() int64

length in bytes for regular files; system-dependent for others

func (*FileInfo) String

func (f *FileInfo) String() string

func (*FileInfo) Sys

func (r *FileInfo) Sys() any

underlying data source (can return nil)

type FileNode added in v0.0.8

type FileNode struct {
	Name     string      `json:"name"`
	Path     string      `json:"path"`
	Type     string      `json:"type"` // "file" or "directory"
	Size     int64       `json:"size,omitempty"`
	Modified time.Time   `json:"modified,omitempty"`
	Children []*FileNode `json:"children,omitempty"`
}

FileNode represents a node in the file tree

type FileStat

type FileStat interface {
	Lstat(name string) (fs.FileInfo, error)
	Stat(name string) (fs.FileInfo, error)
}

type FileStore

type FileStore interface {
	ReadFile(string, *ReadOptions) ([]byte, error)
	WriteFile(string, []byte) error

	// aka:
	// absolute path for file, endpoint for rest, and url for web
	Locator(string) (string, error)
}

type FileSystem

type FileSystem interface {
	FileStore

	ListRoots() ([]string, error)
	ListDirectory(string) ([]string, error)
	CreateDirectory(string) error
	MoveFile(string, string) error
	GetFileInfo(string) (*FileInfo, error)
	DeleteFile(string, bool) error
	CopyFile(string, string) error
	EditFile(string, *EditOptions) (int, error)
	Tree(string, int, bool) (string, error)
	SearchFiles(string, *SearchOptions) (string, error)
}

FileSystem is a virtual file system that provides a set of operations to interact with the file system in a controlled manner.

type LocalFS

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

Local fs is a workspace

func (*LocalFS) CopyFile added in v0.0.8

func (s *LocalFS) CopyFile(
	source string,
	destination string,
) error

Copy files and directories Parameters: source (required): Source path of the file or directory, destination (required): Destination path

func (*LocalFS) CreateDirectory

func (s *LocalFS) CreateDirectory(path string) error

func (*LocalFS) DeleteFile added in v0.0.8

func (s *LocalFS) DeleteFile(
	path string,
	recursive bool,
) error

Delete a file or directory from the file system Parameters: path (required): Path to the file or directory to delete, recursive (optional): Whether to recursively delete directories (default: false)

func (*LocalFS) EditFile added in v0.0.8

func (s *LocalFS) EditFile(
	path string,
	o *EditOptions,
) (int, error)

Update file by finding and replacing text using string matching or regex Parameters: path (required): Path to the file to modify, find (required): Text to search for, replace (required): Text to replace with, all_occurrences (optional): Replace all occurrences (default: true), regex (optional): Treat find pattern as regex (default: false) Return replacement count.

func (*LocalFS) GetFileInfo added in v0.1.3

func (s *LocalFS) GetFileInfo(path string) (*FileInfo, error)

func (*LocalFS) ListDirectory

func (s *LocalFS) ListDirectory(path string) ([]string, error)

func (*LocalFS) ListRoots added in v0.1.3

func (s *LocalFS) ListRoots() ([]string, error)

List allowed top level directories

func (*LocalFS) Locator

func (s *LocalFS) Locator(path string) (string, error)

func (*LocalFS) Lstat

func (s *LocalFS) Lstat(path string) (fs.FileInfo, error)

func (*LocalFS) MoveFile added in v0.1.3

func (s *LocalFS) MoveFile(source, destination string) error

func (*LocalFS) OpenFile

func (s *LocalFS) OpenFile(path string, flag int, perm fs.FileMode) (*os.File, error)

func (*LocalFS) ReadDir

func (s *LocalFS) ReadDir(path string) ([]fs.DirEntry, error)

func (*LocalFS) ReadFile

func (s *LocalFS) ReadFile(path string, o *ReadOptions) ([]byte, error)

ReadFile read raw bytes or content with line numbers if option is provided. path: Absolute or relative file path offset: Line offset to start reading from (0-indexed) limit: Maximum number of lines to read Returns: Formatted file content with line numbers.

func (*LocalFS) ReadMultipleFiles added in v0.1.3

func (s *LocalFS) ReadMultipleFiles(pathsSlice []string) ([]string, error)

func (*LocalFS) SearchFiles

func (s *LocalFS) SearchFiles(path string, options *SearchOptions) (string, error)

Recursively search for files and directories matching a pattern Parameters: path (required): Starting path for the search, pattern (required): Search pattern to match against file names

func (*LocalFS) Stat

func (s *LocalFS) Stat(path string) (fs.FileInfo, error)

func (*LocalFS) Tree added in v0.0.8

func (s *LocalFS) Tree(
	path string,
	depth int,
	follow bool,
) (string, error)

Returns a hierarchical JSON representation of a directory structure Parameters: path (required): Path of the directory to traverse, depth (optional): Maximum depth to traverse (default: 3), follow_symlinks (optional): Whether to follow symbolic links (default: false)

func (*LocalFS) WriteFile

func (s *LocalFS) WriteFile(path string, content []byte) error

type ReadOptions added in v0.0.9

type ReadOptions struct {
	// Number the output lines, starting at 1. (cat -n style).
	Number bool

	// Line offset to start reading from (0-indexed)
	Offset int

	// Maximum number of lines to read. Return the entire file if zero or less
	Limit int
}

type SearchOptions

type SearchOptions struct {
	Pattern string

	// Parse PATTERN as a regular expression
	// Accepted syntax is the same
	// as https://github.com/google/re2/wiki/Syntax
	Regexp bool
	// Match case insensitively
	IgnoreCase bool
	// Only match whole words
	WordRegexp bool
	// Ignore files/directories matching pattern
	Exclude []string
	// Limit search to filenames matching PATTERN
	FileSearchRegexp string
	// Search up to 'Depth' directories deep (default: 25)
	Depth int
	// Follow symlinks
	Follow bool
	// Search hidden files and directories
	Hidden bool
}

type Workspace

type Workspace interface {
	FileSystem
	FileStat

	OpenFile(name string, flag int, perm fs.FileMode) (*os.File, error)
	ReadDir(name string) ([]fs.DirEntry, error)

	ReadMultipleFiles([]string) ([]string, error)
}

func NewLocalFS

func NewLocalFS(allowedDirs []string) (Workspace, error)

Jump to

Keyboard shortcuts

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