forked from pga03/extension-chrome-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_host.js
36 lines (30 loc) · 996 Bytes
/
my_host.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
#!/usr/local/bin/node
// Best to use a direct path on the shebang line in case node isn't in the
// PATH when launched by Chrome.
var fs = require('fs');
var nativeMessage = require('../index');
process.stdin
.pipe(new nativeMessage.Input())
.pipe(new nativeMessage.Transform(function(msg, push, done) {
// If it has a readdir property...
if (msg && msg.readdir) {
// ...reply with a message for each file in that directory.
fs.readdir(msg.readdir, function(err, files) {
if (err) {
push({ error: err.message || err });
} else {
files.forEach(function(file) {
push({ file: file });
});
}
done();
});
} else {
// Just echo the message:
push(msg);
done();
}
}))
.pipe(new nativeMessage.Output())
.pipe(process.stdout)
;