-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.js
More file actions
30 lines (26 loc) · 1 KB
/
client.js
File metadata and controls
30 lines (26 loc) · 1 KB
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
var socketio = require('socket.io-client'),
downloader = require('./downloader'),
log = require('winston'),
url = require('url');
// setup cli
var args = require('optimist').usage('Usage: node server.js --server <server url> --root <root folder>')
.demand(['server', 'root'])
.describe('server', 'the server url')
.describe('root', 'the root folder to synchronize files to').argv;
// connect to server
var io = socketio.connect(args.server).on('error', function(err) {
log.warn('failed to initialize socket.io connection', err);
});
// setup file downloader
var downloader = downloader.downloader(args.root);
// bind change events to downloader
io.on('update', function(file, stat) {
// fix times as socket.io converts them to strings
["atime", "mtime", "ctime"].forEach(function(time) {
if (typeof stat[time] === 'string') {
stat[time] = new Date(stat[time]);
}
});
// download file
downloader.download(url.resolve(args.server, file), stat);
});