Skip to content

@zenfs/dom

Backends for DOM APIs. These are only available natively in browsers.

Terminal window
npm install @zenfs/dom

Reference generated from v1.2.14.

Backend Description
WebAccess Uses the File System Access API, including OPFS.
IndexedDB Stores files in an IndexedDB object database.
WebStorage Stores files in a Storage object, like localStorage and sessionStorage.
XML Uses an XMLDocument to store files, which can be appended to the DOM.

You can use the backends from @zenfs/dom just like the backends from @zenfs/core:

import { configureSingle, fs } from '@zenfs/core';
import { WebStorage } from '@zenfs/dom';
await configureSingle({ backend: WebStorage, storage: localStorage });
if (!fs.existsSync('/test.txt')) {
fs.writeFileSync('/test.txt', 'This will persist across reloads!');
}
const contents = fs.readFileSync('/test.txt', 'utf-8');
console.log(contents);

See Using ZenFS for mounting several backends at once, and the reference for every option each backend accepts.