-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileRequesterBE.js
45 lines (39 loc) · 1.29 KB
/
fileRequesterBE.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
(function (exports) {
var fs = require('fs');
exports.readFileSync = function (path) {
return fs.readFileSync(path);
};
exports.readFile = function (path) {
return new Promise(function (fulfill, reject) {
fs.readFile(path, "utf8", function (err, data) {
if (err) reject(err);
else fulfill(data);
});
});
};
exports.writeFile = function (path, text) {
return new Promise(function (fulfill, reject) {
fs.writeFile(path, text, function (err, data) {
if (err) reject(err);
else fulfill(data);
});
});
};
exports.unlink = function (path) {
return new Promise(function (fulfill, reject) {
fs.unlink(path, function (err) {
if (err) reject(err);
else fulfill();
});
});
};
exports.isFileExist = function (path) {
return new Promise(function (fulfill, reject) {
fs.stat(path, function (err, data) {
if (err === null) fulfill(true);
else if (err.code == "ENOENT") fulfill(false);
else reject(err);
});
});
};
})(this);