-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.js
48 lines (43 loc) · 881 Bytes
/
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
var wallet = require('./build/Release/wallet');
var stream;
exports.stream = function(opts) {
var emitter;
if (opts.emitter) {
emitter = opts.emitter;
} else {
var EventEmitter = require('events');
emitter = new EventEmitter();
}
stream = new wallet.StreamingWorker(function(event, value) {
emitter.emit('data', value);
}, function() {
emitter.emit('close');
}, function(error) {
emitter.emit('error', error);
}, opts);
if (!opts.emitter) {
emitter.on('data', function(value) {
process.stdout.write(value + '\n');
});
}
};
exports.start = function() {
if (stream) {
stream.start();
}
};
exports.pause = function() {
if (stream) {
stream.pause();
}
};
exports.resume = function() {
if (stream) {
stream.resume();
}
};
exports.close = function() {
if (stream) {
stream.closeInput();
}
};