Skip to content

Commit 33e3553

Browse files
committed
add fs.flush() that saves superblock
1 parent 5b69f1c commit 33e3553

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/DefaultBackend.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const path = require("./path.js");
1313
module.exports = class DefaultBackend {
1414
constructor() {
1515
this.saveSuperblock = debounce(() => {
16-
this._saveSuperblock();
16+
this.flush();
1717
}, 500);
1818
}
1919
async init (name, {
@@ -180,4 +180,7 @@ module.exports = class DefaultBackend {
180180
du(filepath) {
181181
return this._cache.du(filepath);
182182
}
183+
flush() {
184+
return this._saveSuperblock();
185+
}
183186
}

src/PromisifiedFS.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,7 @@ module.exports = class PromisifiedFS {
198198
async du(filepath) {
199199
return this._backend.du(filepath);
200200
}
201+
async flush() {
202+
return this._backend.flush();
203+
}
201204
}

src/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module.exports = class FS {
2929
this.symlink = this.symlink.bind(this)
3030
this.backFile = this.backFile.bind(this)
3131
this.du = this.du.bind(this)
32+
this.flush = this.flush.bind(this)
3233
}
3334
init(name, options) {
3435
return this.promises.init(name, options)
@@ -85,4 +86,8 @@ module.exports = class FS {
8586
const [resolve, reject] = wrapCallback(cb);
8687
this.promises.du(filepath).then(resolve).catch(reject);
8788
}
89+
flush(cb) {
90+
const [resolve, reject] = wrapCallback(cb);
91+
this.promises.flush().then(resolve).catch(reject);
92+
}
8893
}

0 commit comments

Comments
 (0)