bro-fs
v0.6.0
Published
Promise-based HTML5 Filesystem API compatible with Node.js fs module
Downloads
1,641
Maintainers
Readme
bro-fs
Promise-based wrapper over HTML5 Filesystem API
allowing to work with sandboxed filesystem in browser.
API is similar to Node.js fs module with some extra sugar.
Currently it is supported only by Chrome.
Demos
API
Install
- install from npm:
npm install bro-fs
- include directly from CDN via
<script>
tag:<script src="https://unpkg.com/bro-fs"></script>
- download manually the latest release
Usage
With async/await
:
const fs = require('bro-fs');
(async function () {
await fs.init({type: window.TEMPORARY, bytes: 5 * 1024 * 1024});
await fs.mkdir('dir');
await fs.writeFile('dir/file.txt', 'hello world');
const content = await fs.readFile('dir/file.txt');
console.log(content); // => "hello world"
})();
or with .then()
:
fs.init({type: window.TEMPORARY, bytes: 5 * 1024 * 1024})
.then(() => fs.mkdir('dir'))
.then(() => fs.writeFile('dir/file.txt', 'hello world'))
.then(() => fs.readFile('dir/file.txt'))
.then(content => console.log(content)); // => "hello world"
See more usage examples in test directory.
W3C Specs
Current:
- https://dev.w3.org/2009/dap/file-system/file-dir-sys.html (Chrome)
- https://wicg.github.io/entries-api (Firefox and Edge)
Coming (draft):
Discussion:
Similar packages
- filer.js - unix-like commands, callbacks
- html5-fs - looks obsolete, callbacks
- chromestore.js - looks obsolete, callbacks
- BrowserFS - many backends, callbacks
- fs-web - store files in IndexedDB, not html5 filesystem
- web-fs - abandoned
- browserify-fs - uses leveldb under hood, callbacks
- fs-browserify - abandoned
- dom-fs - abandoned
License
MIT @ Vitaliy Potapov