I've got a compressed gzip file which I would like to read line by line.
var fs = require('fs')
var zlib = require('zlib')
var gunzip = zlib.createGunzip()
var inp = fs.createReadStream('test.gz')
var n = 0
var lineProcessing = function (err, data) {
if (!err) {
n += 1
console.log ("line: " + n)
console.log (data.toString())
}
}
inp
.on('data', function (chunk) {
zlib.gunzip (chunk, lineProcessing)
})
.on('end', function () {
console.log ('ende');
});
I guess I need to set a chunksize for zlib.createGunzip
that I only read until the next \n
. But how to determine it dynamically?