BaseVFS. Override readdir, stat and
read, and ls, cat, grep, find and the other read commands work on
your service. Every other method is optional: override one, and the commands
that need it start working, or answer with fewer requests.
The base class
The methods you can override, with the arguments you normally use:- Python
- TypeScript
How to integrate your service
Required
Write
Writes need a writable mount:MountMode.WRITE, or mode: write in YAML.
Answer commands with your service
Override these to answer from your service’s own search, query or metadata API instead of reading files. Each links to its guide.Attributes
Set them as class attributes or pass them to
super().__init__()
(super({...}) in TypeScript).
Example: a read-only VFS
This VFS serves pages from a dictionary:- Python
- TypeScript
notes.py
- Python
- TypeScript
- YAML
cat /notes/hello.txt then prints hello mirage, and grep -rn mirage /notes
reads every page. In YAML, vfs names the class as file:Class, relative to
the YAML file, and config is what its constructor gets; the TypeScript server
takes ./notes.ts:NotesVFS. To name it vfs: notes instead, register it with
register_vfs in Python or registerVfs in TypeScript.
Example: make it writable
Overridewrite and unlink:
- Python
- TypeScript
echo hi > /notes/new.txt, sed -i and rm now work,
and >> reads the page and writes it back. mv still answers
Operation not supported until you override rename.
Example: let grep use your search
Overridefiles_containing to name the files that may contain the text:
- Python
- TypeScript
grep -rn mirage /notes now reads only the pages this returns, and Mirage
still checks each line, so the output is the same. The dictionary stands in
for your service’s search API. mounted_path turns a name inside the mount
into a path. grep -ri gets None here, so it reads every page.
For a real one, see Chroma, the
search behind a RAG knowledge base: its files_containing asks Chroma for the
chunks whose text contains the word ($contains) and returns their pages, and
it also returns None for -i. Source:
Python,
TypeScript.
Example: count lines without reading
Overrideline_count:
- Python
- TypeScript
wc -l /notes/hello.txt now answers without reading the page. For a database,
this is where a count(*) query goes. Plain wc still reads the page, since it
also counts words and bytes.