Skip to main content

What is the file system module?

fs is a small wrapper over the native file manager. Use it to read, write, remove, and check files. By default, every path resolves against the platform’s documents directory (the private, persistent folder where Unbound stores its data), so you can use short relative paths instead of absolute ones. fs is built on the native bridge. storage and i18n persist their data through it: when you call storage.set, fs is what eventually writes the value to disk.

Reading & writing

read and write default to utf8 encoding. read resolves to the file’s contents, and write resolves once the file is on disk. If you need the absolute documents path, it’s in fs.Documents.
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 checks whether a file exists, and rm deletes it. Both resolve to a boolean.
For configuration, use storage instead. Use fs directly when an addon ships its own data files, such as caches, exports, or downloaded assets, that don’t belong in the settings store.