-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
79 lines (74 loc) · 1.85 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import csv from 'csv-parser';
import {
unlink,
createWriteStream,
createReadStream
} from 'fs';
import {
argv
} from 'yargs';
import {emptyDir} from 'fs-extra';
if (!argv.input) {
console.log('No input file set. Use npm start -- --input=<path>');
process.exit(1);
}
emptyDir('output', (err) => {
if (err) {
console.log('Unable to clean output directory!');
process.exit(1);
}
});
let writeStream = createWriteStream('output/output.csv', {
flags: 'ax',
});
let stream = csv({
raw: false, // do not decode to utf-8 strings
separator: ',', // specify optional cell separator
quote: '"', // specify optional quote character
escape: '"', // specify optional escape character (defaults to quote value)
newline: '\n', // specify a newline character
strict: false,
headers: [
'PartitionKey',
'RowKey',
'Timestamp',
'Partition',
'blockId',
'directionCode',
'entitynumber',
'internalLinenumber',
'restString0',
'restString1',
'restString2',
'timeOfFirstStop',
'timeOfLastStop',
'tripnumber',
'restString3',
'restString4',
'restString5',
'restString6',
],
});
createReadStream(argv.input)
.pipe(stream)
.on('data', function (data) {
writeStream.write(
data.PartitionKey +
',' +
data.internalLinenumber +
',' +
data.tripnumber +
',' +
data.restString0 +
data.restString1 +
data.restString2 +
data.restString3 +
data.restString4 +
data.restString5 +
data.restString6
);
})
.on('error', function (err) {
console.log('Failed to process input: ' + err);
process.exit(1)
});