![](/img/trans.png)
[英]Replacing fs.readFile with fs.createReadStream in Node.js
[英]fs.createReadStream only reading last line of file node.js
嗨,我正在尝试简单地流式传输csv文件的内容,并且遇到了一些非常烦人的问题。 贝娄是我的代码,我的挫败感隐藏在我的评论中。
var fileReadStream = fs.createReadStream(inFile);
// For some reason readable will yield only the last line of my file
// and if I listen for 'data' I still just get the last line of my file
fileReadStream.on('readable', function() {
process.stdout.write(fileReadStream.read().toString());
}).on('end', function() {
i ++;
next();
});
任何帮助都会很棒。 我也很困惑如何正确地制作东西。 从我的解释来看,我觉得对于管道对象,管道将简单地写入管道内部的对象,然后对该对象调用read。 但是我一直无法使管道正常工作。 也许当我解决这个问题时,我可以更轻松地找出管道。 谢谢。
您应该能够简单地执行以下操作:
var fileReadStream = fs.createReadStream(inFile);
fileReadStream.on('end', function() {
i++;
next();
}).pipe(process.stdout);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.