Skip to content

Commit 78799b2

Browse files
committed
simplify
1 parent ff5e414 commit 78799b2

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

src/PromisifiedFS.js

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,38 +40,34 @@ function cleanParamsFilepathFilepath(oldFilepath, newFilepath, ...rest) {
4040
return [path.normalize(oldFilepath), path.normalize(newFilepath), ...rest];
4141
}
4242

43-
module.exports = function promises(name, options) {
44-
const pfs = new PromisifiedFS(options);
45-
pfs.init = pfs.init.bind(pfs)
46-
pfs.readFile = pfs._wrap(pfs.readFile, cleanParamsFilepathOpts, false)
47-
pfs.writeFile = pfs._wrap(pfs.writeFile, cleanParamsFilepathDataOpts, true)
48-
pfs.unlink = pfs._wrap(pfs.unlink, cleanParamsFilepathOpts, true)
49-
pfs.readdir = pfs._wrap(pfs.readdir, cleanParamsFilepathOpts, false)
50-
pfs.mkdir = pfs._wrap(pfs.mkdir, cleanParamsFilepathOpts, true)
51-
pfs.rmdir = pfs._wrap(pfs.rmdir, cleanParamsFilepathOpts, true)
52-
pfs.rename = pfs._wrap(pfs.rename, cleanParamsFilepathFilepath, true)
53-
pfs.stat = pfs._wrap(pfs.stat, cleanParamsFilepathOpts, false)
54-
pfs.lstat = pfs._wrap(pfs.lstat, cleanParamsFilepathOpts, false)
55-
pfs.readlink = pfs._wrap(pfs.readlink, cleanParamsFilepathOpts, false)
56-
pfs.symlink = pfs._wrap(pfs.symlink, cleanParamsFilepathFilepath, true)
57-
pfs.backFile = pfs._wrap(pfs.backFile, cleanParamsFilepathOpts, true)
58-
pfs.du = pfs._wrap(pfs.du, cleanParamsFilepathOpts, false);
43+
module.exports = class PromisifiedFS {
44+
constructor(name, options = {}) {
45+
this.init = this.init.bind(this)
46+
this.readFile = this._wrap(this.readFile, cleanParamsFilepathOpts, false)
47+
this.writeFile = this._wrap(this.writeFile, cleanParamsFilepathDataOpts, true)
48+
this.unlink = this._wrap(this.unlink, cleanParamsFilepathOpts, true)
49+
this.readdir = this._wrap(this.readdir, cleanParamsFilepathOpts, false)
50+
this.mkdir = this._wrap(this.mkdir, cleanParamsFilepathOpts, true)
51+
this.rmdir = this._wrap(this.rmdir, cleanParamsFilepathOpts, true)
52+
this.rename = this._wrap(this.rename, cleanParamsFilepathFilepath, true)
53+
this.stat = this._wrap(this.stat, cleanParamsFilepathOpts, false)
54+
this.lstat = this._wrap(this.lstat, cleanParamsFilepathOpts, false)
55+
this.readlink = this._wrap(this.readlink, cleanParamsFilepathOpts, false)
56+
this.symlink = this._wrap(this.symlink, cleanParamsFilepathFilepath, true)
57+
this.backFile = this._wrap(this.backFile, cleanParamsFilepathOpts, true)
58+
this.du = this._wrap(this.du, cleanParamsFilepathOpts, false);
5959

60-
if (name) {
61-
pfs.init(name, options)
62-
}
63-
return pfs;
64-
}
65-
66-
class PromisifiedFS {
67-
constructor(options = {}) {
6860
this._backend = options.backend || new DefaultBackend();
6961

7062
this._deactivationPromise = null
7163
this._deactivationTimeout = null
7264
this._activationPromise = null
7365

7466
this._operations = new Set()
67+
68+
if (name) {
69+
this.init(name, options)
70+
}
7571
}
7672
async init (...args) {
7773
if (this._initPromiseResolve) await this._initPromise;

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const once = require("just-once");
22

3-
const promises = require('./PromisifiedFS');
3+
const PromisifiedFS = require('./PromisifiedFS');
44

55
function wrapCallback (opts, cb) {
66
if (typeof opts === "function") {
@@ -13,7 +13,7 @@ function wrapCallback (opts, cb) {
1313

1414
module.exports = class FS {
1515
constructor(...args) {
16-
this.promises = promises(...args)
16+
this.promises = new PromisifiedFS(...args)
1717
// Needed so things don't break if you destructure fs and pass individual functions around
1818
this.init = this.init.bind(this)
1919
this.readFile = this.readFile.bind(this)

0 commit comments

Comments
 (0)