0.1.1 • Published 2 months ago
@browserfs/dom v0.1.1
BrowserFS DOM Backends
BrowserFS backends for DOM APIs. DOM APIs are only available natively in browsers.
!IMPORTANT Please read the BrowserFS core documentation!
Backends
Storage
: Stores files in aStorage
object, likelocalStorage
andsessionStorage
.IndexedDB
: Stores files into anIndexedDB
object database.FileSystemAccess
: Store files using the Web File System API.
For more information, see the API documentation.
Usage
!NOTE
The examples are written in ESM. If you are using CJS, you canrequire
the package. If running in a browser you can add a script tag to your HTML pointing to thebrowser.min.js
and use BrowserFS DOM via the globalBrowserFS_DOM
object.
import { configure, fs } from '@browserfs/core';
import { Storage } from '@browserfs/dom';
await configure({ backend: Storage, 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);