-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.js
28 lines (28 loc) · 829 Bytes
/
parser.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
var csv = require("csv"),
fs = require("fs"),
parser = csv.parse({delimiter:",",escape:'"',from:2}),
transform = csv.transform(function(data) {
return [data[0].substr(0,10).replace(/\./g,"/"),data[1] + ":" + data[2],data[3]]
}),
stringify = csv.stringify({delimiter:"\t"}),
res = "";
parser.on("readable",function() {
while(data = parser.read()) {
transform.write(data);
}
})
transform.on("readable",function() {
while(data = transform.read()) {
stringify.write(data);
}
})
stringify.on("readable",function() {
//res += stringify.read();
ws.write(stringify.read());
})
parser.on("finish",function() {
ws.close();
})
var rs = fs.createReadStream("/home/jakob/node/test.csv"),
ws = fs.createWriteStream("/home/jakob/node/output.csv");
rs.pipe(parser);