Skip to main content

What is the file system module?

fs is a small wrapper over the native file manager for reading, writing, removing, and checking files. By default every path resolves against the platform’s documents directory (the private, persistent folder Unbound stores its data in), so you work with short relative paths instead of absolute ones. It’s built on the native bridge, and it’s the layer storage and i18n persist through. When you storage.set something, this is what eventually writes it to disk.
import { fs } from '@unbound-app/api';

await fs.write('my-plugin/data.json', JSON.stringify({ count: 1 }));
const raw = await fs.read('my-plugin/data.json');

Reading & writing

read and write default to utf8. read resolves to the file’s contents; write resolves once the file is on disk. fs.Documents holds the absolute documents path if you need it.
import { fs } from '@unbound-app/api';

await fs.write('my-plugin/notes.txt', 'hello');
Relative paths resolve against fs.Documents. To read a file elsewhere on disk, pass an absolute path and false as the inDocuments argument: fs.read('/abs/path', 'utf8', false).

Checking & removing

exists tells you whether a file is there; rm deletes it. Both resolve to a boolean.
import { fs } from '@unbound-app/api';

if (await fs.exists('my-plugin/data.json')) {
	await fs.rm('my-plugin/data.json');
}
You rarely need this for configuration; let storage own that. Reach for fs directly when an addon ships its own data files (caches, exports, downloaded assets) that don’t belong in the settings store.