-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
60 lines (40 loc) · 1.14 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
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* A module for manage file dialogs in node-webkit.
* @module FDialogs
*/
'use strict';
var FDialog = require('./lib/fdialog');
module.exports = {
FDialog: FDialog,
/** Display dialog and get Path */
getFilePath: function (cb) {
var fd = new FDialog();
fd.getFilePath(cb);
},
/** Display dialog and return content and path of a file */
readFile: function (defaultPath, cb) {
if (typeof defaultPath == 'function') {
cb = defaultPath;
defaultPath = null;
}
var fd = new FDialog({
path: defaultPath,
type: 'open'
});
fd.readFile(cb);
},
/** Display dialog and save content in a file */
saveFile: function (data,defaultPath, cb) {
if (!Buffer.isBuffer(data))
throw new Error("Data should be a Buffer");
if (typeof defaultPath == 'function') {
cb = defaultPath;
defaultPath = null;
}
var fd = new FDialog({
type: 'save',
defaultSavePath: defaultPath
});
fd.saveFile(data, cb);
}
};