-
Notifications
You must be signed in to change notification settings - Fork 4
/
stream.js
58 lines (46 loc) · 1.23 KB
/
stream.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
'use strict';
// !-- FOR TESTS
let wrapper = function (options) {
// --!
// =====================================================
// <EXAMPLE>
const fs = require('fs');
let Beelzebub = require('../../');
let bz = Beelzebub(options || { verbose: true });
class MyTasks extends Beelzebub.Tasks {
constructor (config) {
super(config);
this.$setName('MyTasks');
}
task1 () {
var data = '';
var stream = fs.createReadStream('./static-files/src/file1.txt');
stream.setEncoding('utf8');
stream.on('data', (chunk) => {
data += chunk;
});
stream.on('end', () => {
this.logger.log('MyTasks task1 data size:', data.length);
// this.logger.log('MyTasks task1 data:', data);
});
return stream;
}
task2 () {
this.logger.log('MyTasks task2');
}
}
bz.add(MyTasks);
let p = bz.run('MyTasks.task1', 'MyTasks.task2');
/* Output:
MyTasks task1 data size: 840
MyTasks task2
*/
// </EXAMPLE>
// =====================================================
// !-- FOR TESTS
return p.then(() => { return bz; });
};
module.exports = wrapper;
// if not running in test, then run wrapper
if (typeof global.it !== 'function') wrapper();
// --!