vfs

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package vfs provides a virtual filesystem abstraction over Trove object storage. It adapts flat object key spaces into hierarchical directory structures, enabling familiar file-system operations (Stat, ReadDir, Walk, Open, Create, Remove, Rename) and compatibility with Go's io/fs.FS interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DirEntry

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

DirEntry is a directory entry returned by ReadDir.

func (DirEntry) Info

func (de DirEntry) Info() (fs.FileInfo, error)

func (DirEntry) IsDir

func (de DirEntry) IsDir() bool

func (DirEntry) Name

func (de DirEntry) Name() string

func (DirEntry) Type

func (de DirEntry) Type() fs.FileMode

type FS

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

FS provides a virtual filesystem over Trove object storage. Object keys are treated as file paths with "/" as the directory separator.

func New

func New(store Storage, bucket string) *FS

New creates a new VFS for the given storage and bucket.

func (*FS) Create

func (f *FS) Create(ctx context.Context, name string) (*File, error)

Create creates or overwrites a file. The caller must Close the returned File to flush the data to storage.

func (*FS) GetMetadata

func (f *FS) GetMetadata(ctx context.Context, name string) (map[string]string, error)

GetMetadata returns metadata for a file.

func (*FS) Mkdir

func (f *FS) Mkdir(ctx context.Context, name string) error

Mkdir creates a directory marker object. This is a zero-length object with a trailing "/" in the key.

func (*FS) Open

func (f *FS) Open(ctx context.Context, name string) (*File, error)

Open opens a file for reading.

func (*FS) ReadDir

func (f *FS) ReadDir(ctx context.Context, name string) ([]DirEntry, error)

ReadDir lists entries in a directory.

func (*FS) Remove

func (f *FS) Remove(ctx context.Context, name string) error

Remove removes a file.

func (*FS) RemoveAll

func (f *FS) RemoveAll(ctx context.Context, name string) error

RemoveAll removes a path and all children.

func (*FS) Rename

func (f *FS) Rename(ctx context.Context, oldName, newName string) error

Rename moves a file from oldName to newName.

func (*FS) SetMetadata

func (f *FS) SetMetadata(ctx context.Context, name string, meta map[string]string) error

SetMetadata sets metadata on a file by copying it with updated metadata.

func (*FS) Stat

func (f *FS) Stat(ctx context.Context, name string) (*FileInfo, error)

Stat returns file info for the given path.

func (*FS) Walk

func (f *FS) Walk(ctx context.Context, root string, fn WalkFunc) error

Walk traverses the file tree rooted at root, calling fn for each file or directory.

type File

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

File represents an open VFS file backed by object storage.

func (*File) Close

func (f *File) Close() error

Close closes the file, flushing any pending writes.

func (*File) Name

func (f *File) Name() string

Name returns the file name.

func (*File) Read

func (f *File) Read(p []byte) (int, error)

Read reads from the file (only valid for files opened with Open).

func (*File) Stat

func (f *File) Stat() (*FileInfo, error)

Stat returns the FileInfo for this file.

func (*File) Write

func (f *File) Write(p []byte) (int, error)

Write writes to the file (only valid for files created with Create).

type FileInfo

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

FileInfo implements os.FileInfo for VFS entries.

func (*FileInfo) IsDir

func (fi *FileInfo) IsDir() bool

func (*FileInfo) ModTime

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

func (*FileInfo) Mode

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

func (*FileInfo) Name

func (fi *FileInfo) Name() string

func (*FileInfo) Size

func (fi *FileInfo) Size() int64

func (*FileInfo) Sys

func (fi *FileInfo) Sys() any

type IOFS

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

IOFS adapts a Trove VFS to Go's io/fs.FS interface, enabling use with http.FileServer(http.FS(vfs)), template.ParseFS, and other stdlib consumers.

func NewIOFS

func NewIOFS(ctx context.Context, vfs *FS) *IOFS

NewIOFS creates an io/fs.FS adapter for the VFS. The provided context is used for all operations.

func (*IOFS) Open

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

Open implements fs.FS.

type Storage

type Storage interface {
	Put(ctx context.Context, bucket, key string, r io.Reader, opts ...driver.PutOption) (*driver.ObjectInfo, error)
	Get(ctx context.Context, bucket, key string, opts ...driver.GetOption) (*driver.ObjectReader, error)
	Delete(ctx context.Context, bucket, key string, opts ...driver.DeleteOption) error
	Head(ctx context.Context, bucket, key string) (*driver.ObjectInfo, error)
	List(ctx context.Context, bucket string, opts ...driver.ListOption) (*driver.ObjectIterator, error)
	Copy(ctx context.Context, srcBucket, srcKey, dstBucket, dstKey string, opts ...driver.CopyOption) (*driver.ObjectInfo, error)
}

Storage defines the subset of Trove operations needed by VFS. This avoids a circular import with the trove package.

type WalkFunc

type WalkFunc func(path string, info *FileInfo, err error) error

WalkFunc is the callback for Walk.

Jump to

Keyboard shortcuts

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