-
Notifications
You must be signed in to change notification settings - Fork 0
/
exports.js
47 lines (40 loc) · 1.2 KB
/
exports.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');
module.exports = {
"open": function (file) {
var context = this;
var fileName = file;
context.async = true;
console.log("fileName", file);
fs.exists(fileName, function (exists) {
if (!exists) return this.return("this file does not exist");
fs.stat(fileName, function (err, stats) {
if (err) return send(err);
if (stats.isDirectory())
context.return(new Error("Editing directories in a text editor is not currently supported"));
fs.readFile(fileName, function (err, data) {
if (err) return context.return(err);
var ret = {
state: "ready",
content: data.toString("utf-8")
}
context.return(ret);
})
});
});
},
"save": function (data, callObj, send) {
var fs = require("fs");
console.log(data);
path = data.path;
contents = data.contents;
console.log("==========");
// console.log(contents);
fs.writeFile(path, contents, function (err) {
if (err) return console.log(err);
console.log("saved: " + path);
});
console.log("finished");
// tricks silk into sending return value;
return " ";
}
};