Chroma-Fs
API
ChromaFs class and createChromaFs factory — unified storage API for IndexedDB and filesystem backends.
createChromaFs(options?)
Factory that resolves config, detects platform, and returns a ChromaFs instance.
import { createChromaFs } from "@chroma/fs";
const fs = await createChromaFs({
configPath: "./chroma-fs.json",
});Options (CreateStorageOptions)
| Field | Type | Description |
|---|---|---|
config | Partial<ChromaFsConfig> | Inline config override |
configPath | string | URL/path to fetch chroma-fs.json (default: tries ./chroma-fs.json) |
adapter | TauriFsAdapter | Custom adapter (testing or custom bridge) |
ChromaFs methods
All methods are async and use forward-slash paths relative to the storage root.
| Method | Description |
|---|---|
readFile(path) | Returns Uint8Array |
readText(path) | Returns UTF-8 string |
writeFile(path, data) | data is string or Uint8Array |
delete(path) | Removes file or directory (recursive for directories) |
exists(path) | boolean |
list(path?) | Direct children as FileEntry[] |
mkdir(path) | Creates directory (parents created implicitly on write) |
rmdir(path, { recursive? }) | Removes empty dir, or recursive |
stat(path) | FileEntry or null |
FileEntry
interface FileEntry {
name: string;
path: string;
kind: "file" | "directory";
size?: number;
modifiedAt?: number;
}Utilities
Re-exported from @chroma/fs for path normalization and config:
loadConfig,parseConfig,mergeConfig,defaultConfigdetectPlatform,resolveBackendnormalizePath,joinPath,parentPath,baseNamecreatePostMessageAdapter,isInIframe,hasTauriRuntimecreateDefaultTauriFsAdapter— direct Tauri plugin-fs wrapper
Example (dynamic template)
import { createChromaFs } from "@chroma/fs";
let fsPromise = null;
export function getFs() {
if (!fsPromise) {
fsPromise = createChromaFs({ configPath: "./chroma-fs.json" });
}
return fsPromise;
}
export async function saveSettings(settings) {
const fs = await getFs();
await fs.writeFile("settings.json", JSON.stringify(settings, null, 2));
}