-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.js
More file actions
32 lines (29 loc) · 775 Bytes
/
Copy pathtest.js
File metadata and controls
32 lines (29 loc) · 775 Bytes
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
var decoder = require('./decode.js');
var fs = require('fs');
var stream = fs.createReadStream("filter_data.log");
function readLines(input, func) {
var remaining = '';
input.on('data', function(data) {
remaining += data;
var index = remaining.indexOf('\n');
while (index > -1) {
var line = remaining.substring(0, index);
remaining = remaining.substring(index + 1);
func(line);
index = remaining.indexOf('\n');
}
});
input.on('end', function() {
if (remaining.length > 0) {
func(remaining);
}
});
}
function func(line) {
var myDate = new Date();
line = line.substring(line.indexOf(']') + 1);
console.log(line);
var haha = decoder.decode(line, myDate);
console.log(haha);
}
readLines(stream, func);