parsing-huge-logfiles-in-node-js-read-in-line-by-line
2016. 9. 23. 10:56ㆍMeteor
http://stackoverflow.com/questions/16010915/parsing-huge-logfiles-in-node-js-read-in-line-by-line
var fs = require('fs')
, util = require('util')
, stream = require('stream')
, es = require('event-stream');
var lineNr = 0;
var s = fs.createReadStream('very-large-file.csv')
.pipe(es.split())
.pipe(es.mapSync(function(line){
// pause the readstream
s.pause();
lineNr += 1;
// process line here and call s.resume() when rdy
// function below was for logging memory usage
logMemoryUsage(lineNr);
// resume the readstream, possibly from a callback
s.resume();
})
.on('error', function(){
console.log('Error while reading file.');
})
.on('end', function(){
console.log('Read entire file.')
})
);
'Meteor' 카테고리의 다른 글
오라클 DB Link 속도 저하 문제 (0) | 2017.01.29 |
---|---|
Microservices with Meteor (0) | 2016.09.29 |
meteor SSL 설정(HTTPS(nginx) -> HTTP(meteor)) 진행중... (0) | 2016.08.30 |
웹사이트 정보를 확인하는 유용한 정보 (0) | 2016.07.23 |
Meteor installation failed on Windows 10 (0) | 2016.03.18 |