-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.js
executable file
·54 lines (54 loc) · 1.26 KB
/
utils.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
48
49
50
51
52
53
54
"use strict";
var fs = require('fs');
function fileExists(file) {
var statFile;
var ret;
try {
statFile = fs.statSync(file);
ret = statFile.isFile();
}
catch (e) {
ret = false;
}
return ret;
}
exports.fileExists = fileExists;
function pathExists(path) {
var statFile;
var ret;
try {
statFile = fs.statSync(path);
ret = statFile.isDirectory();
}
catch (e) {
ret = false;
}
return ret;
}
exports.pathExists = pathExists;
function readFile(file, encoding) {
if (!fileExists(file)) {
return null;
}
encoding = encoding || 'utf8';
return fs.readFileSync(file, { encoding: encoding });
}
exports.readFile = readFile;
function writeOnFile(file, content, encoding) {
encoding = encoding || 'utf8';
var writeSync = fs.writeFileSync(file, content, { encoding: encoding });
return (writeSync === undefined);
}
exports.writeOnFile = writeOnFile;
function removeFile(file) {
if (!fileExists(file)) {
return false;
}
var unlinkSync = fs.unlinkSync(file);
return (unlinkSync === undefined);
}
exports.removeFile = removeFile;
function isCorrectPort(port) {
return (port >= 0 && port <= 65535);
}
exports.isCorrectPort = isCorrectPort;