-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathindex.js
47 lines (39 loc) · 1.06 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var fs = require('fs');
// Detect presence of fs.statfs
if(typeof fs.statfs === 'function') {
exports.check = function(path, callback) {
if (callback) {
return check(path, callback);
}
return new Promise(function (resolve, reject) {
check(path, function (err, result) {
err ? reject(err) : resolve(result);
});
});
}
function check(path, callback) {
fs.statfs(path, function (err, result_) {
var result = undefined;
if (!err) {
result = {
available: result_.bavail * result_.bsize,
free: result_.bfree * result_.bsize,
total: result_.blocks * result_.bsize
};
}
callback(err, result);
});
}
exports.checkSync = function(path) {
var result = fs.statfsSync(path);
return {
available: result.bavail * result.bsize,
free: result.bfree * result.bsize,
total: result.blocks * result.bsize
}
}
} else {
var diskusage = require('./fallback.js');
exports.check = diskusage.check;
exports.checkSync = diskusage.checkSync;
}