tail-stream module in nodejs is not printing last record of the file

半城伤御伤魂 提交于 2019-12-20 07:29:22

问题


I am using tail-stream to get data from a csv file and converting each csv record to json format and printing it.

But tail-stream is not printing the last line of the file it is keeping it as a buffer, and if I update the file all the rows from previous last(the buffered last row) row to updated last row(excluding last row) are printed, its again storing the latest last row in buffer

So is this the behavior of the tail-stream or is there any wrong in my code

https://www.npmjs.com/package/tail-stream

My code:

var tailStream      = require('tail-stream');
var Converter       = require("csvtojson").Converter;
var converter  = new Converter({constructResult:false});

var logStream = tailStream.createReadStream('issue_Approver_Rohit1.csv', {
    beginAt: 0,
    onMove: 'follow',
    detectTruncate: false,
    onTruncate: 'end',
    endOnError: false
});


logStream.pipe(converter);


converter.on("record_parsed", function (jsonObj) {
        console.log(jsonObj); //here is your result json object

    });

});

来源:https://stackoverflow.com/questions/33933201/tail-stream-module-in-nodejs-is-not-printing-last-record-of-the-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!