embedfs

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package embedfs adapts any fs.FS (including embed.FS) to vfs.Storage.

The backend is read-only: WriteFile and DeleteFile return vfs.ErrReadOnly. Suitable for chatbot/knowledge-base use cases where the corpus is fixed at compile time and the model only reads.

import _ "embed"

//go:embed knowledge/*.md
var knowledgeFS embed.FS

knowledge, _ := fs.Sub(knowledgeFS, "knowledge")
storage := embedfs.NewStorage(knowledge)

Storage satisfies vfs.Searchable with case-insensitive substring matching against file contents — same syntax as vfs/memory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Storage

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

Storage wraps an fs.FS as a read-only vfs.Storage.

func NewStorage

func NewStorage(fsys fs.FS) *Storage

NewStorage wraps fsys. The fsys is consulted on every call; nothing is cached.

Caller-bound subdirectories: pass fs.Sub(fsys, "data") if your embed includes a parent prefix you want to hide from the model.

func (*Storage) DeleteFile

func (s *Storage) DeleteFile(_ context.Context, p string) error

DeleteFile always returns vfs.ErrReadOnly.

func (*Storage) ListFiles

func (s *Storage) ListFiles(ctx context.Context) ([]vfs.FileMeta, error)

ListFiles walks the entire fs and returns every file (no directories). Paths are relative; deterministic alphabetical order.

func (*Storage) ReadFile

func (s *Storage) ReadFile(ctx context.Context, p string) ([]byte, vfs.FileMeta, error)

ReadFile returns the bytes for the requested path.

func (*Storage) Search

func (s *Storage) Search(ctx context.Context, query string) ([]string, error)

Search performs a case-insensitive substring search against file contents.

func (*Storage) SearchSyntax

func (s *Storage) SearchSyntax() string

SearchSyntax describes the query syntax this backend accepts.

func (*Storage) WriteFile

func (s *Storage) WriteFile(_ context.Context, p string, _ []byte, _ string) error

WriteFile always returns vfs.ErrReadOnly.

Jump to

Keyboard shortcuts

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