-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
64 lines (52 loc) · 1.55 KB
/
main.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
61
62
63
64
const { transform } = require('stream-transform');
const fs = require('fs');
const { taxonTransform, parser, stringifier } = require("./taxonTransform.js");
var inputFile = process.argv[2];
var issuesFile = process.argv[3];
var readStream = fs.createReadStream(inputFile);
var issuesStream = fs.createWriteStream(issuesFile);
Object.defineProperty(String.prototype, 'capitalize', {
value: function() {
return this.charAt(0).toUpperCase() + this.slice(1);
},
enumerable: false
});
const issues = [];
stringifier.on('readable', function(){
let row;
while((row = stringifier.read()) !== null){
issues.push(row);
}
});
// Catch any error in issues pipe
stringifier.on('error', function(err){
error(err.message);
});
// When finished
stringifier.on('finish', function(){ });
// Write records to the stream
stringifier.pipe(issuesStream);
var atFirstLine = true;
var stats = { authorWithQuote: 0, scientifiNameWithUnderscore: 0, splitted: 0, total: 0 }
const transformer = transform(function(record) {
if (atFirstLine) {
// we skip the first line
atFirstLine = false;
stringifier.write(record.concat([ "Issue" ]));
} else {
record = taxonTransform(record, stats);
}
return record.join('\t')+'\n';
});
readStream.on('open', function () {
readStream.pipe(parser).pipe(transformer).pipe(process.stdout); // taxonResultStream); //
});
readStream.on('end', () => {
console.error(JSON.stringify(stats));
});
readStream.on('error', function(err) {
error(err);
stringifier.end();
readStream.destroy();
// readStream.end(err);
});