zen-fs / dom

DOM backends for ZenFS
https://zen-fs.github.io/dom/
MIT License
11 stars 2 forks source link
browserfs zenfs

ZenFS DOM Backends

ZenFS backends for DOM APIs. DOM APIs are only available natively in browsers.

[!IMPORTANT] Please read the ZenFS core documentation!

Backends

For more information, see the API documentation.

Usage

[!NOTE] The examples are written in ESM.
For CJS, you can require the package.
For a browser environment without support for type=module in script tags, you can add a script tag to your HTML pointing to the browser.min.js and use the global ZenFS_DOM object.

import { configure, fs } from '@zenfs/core';
import { WebStorage } from '@zenfs/dom';

await configure({ 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);