opfs
v1.1.1
Published
yet another node fs wrapper
Downloads
44
Maintainers
Readme
opfs
Yet another node fs wrapper.
- With promisfied methods that still work with callbacks.
- Set your own custom Promise.
- Non constructor functions bound to fs.
- All other original properties transferred as is.
- No dependencies.
- Optional pkgs promisified and added: mkdirp, rimraf.
- Save full caller stack (10-20% performance penalty)
Install
npm install --save opfs
Usage
const opfs = require("opfs");
// Set custom Promise to bluebird. This is automatic if
// it's found in your package.json and node_modules.
opfs._opfsSetPromise(require("bluebird"));
// To use native Promise even if bluebird was found.
opfs._opfsSetPromise();
// To turn off save full caller stack
opfs._opfsSaveStack(false);
// promise APIs
opfs
.readFile("foo.text")
.then(data => {})
.catch(err => {});
// native promises methods (if available) node 10+
opfs.promises
.readFile("foo.text")
.then(data => {})
.catch(err => {});
// callback still works
opfs.readFile("foo.text", (err, data) => {});
//
// optional pkgs (if found in your package.json and node_modules)
//
// mkdirp
opfs.$.mkdirp("a/b/c").then(() => {});
opfs.$.mkdirpSync("a/b/c");
// rimraf
opfs.$.rimraf("a").then(() => {});
opfs.$.rimrafSync("a");
// All other fs props transferred
console.log(typeof opfs.Stats);
console.log(typeof opfs.readFileSync);
console.log(typeof opfs.F_OK);
console.log(typeof opfs.W_OK);
License
Copyright (c) 2018-present, Joel Chen
Licensed under the Apache License, Version 2.0.