Demonstrates the core AFS operations — mount providers, list directories, read files, search content, write files, and inspect metadata.
- Mount a local directory and a JSON config file as AFS providers
- List directory contents (files and subdirectories)
- Read a file's content
- Navigate JSON as a virtual directory tree (objects become folders, values become files)
- Search for text patterns across all mounted files
- Write a new file through AFS
- Stat a file for metadata without reading its content
bun index.tsAFS Basic Example
Mounted providers:
/project → afs-example-...
/config → config
--- List /project ---
📄 /README.md
📄 /config.json
📄 /src
--- List /project/src ---
📄 /src/index.ts (56 bytes)
📄 /src/utils.ts (63 bytes)
--- Read /project/README.md ---
# My Project
A sample project.
--- Navigate /config (JSON as directories) ---
📄 /name
📄 /version
📄 /features
config.name = "my-app"
config.features → /features/auth, /features/api
--- Search for 'TODO' in /project ---
/project/src/utils.ts: match found
--- Write /project/output.txt ---
Written: Generated by AFS example
--- Stat /project/src/index.ts ---
size: 56 bytes
Done!
Every data source is a provider that you mount at a path. Once mounted, all AFS operations work uniformly regardless of the underlying storage.
const afs = new AFS();
await afs.mount(new AFSFS({ localPath: "./my-dir" }), "/project");
await afs.mount(new AFSJSON({ localPath: "./config.json" }), "/config");The JSON provider (@aigne/afs-json) maps JSON structure to directories and files:
- Objects and arrays become directories you can
list - Primitive values become files you can
read - Changes via
writepersist back to the original JSON file
Every provider supports the same operations: list, read, write, search, stat, explain, exec. Your code doesn't need to know what's behind the path.
@aigne/afs— Core AFS library@aigne/afs-fs— Local filesystem provider@aigne/afs-json— JSON virtual filesystem provider