Node.js readline缺less文件的最后一行?

我试图读取一个文本文件asynchronous和​​逐行Node.js下。 我有以下CoffeeScript代码:

readline = require 'readline' fs = require 'fs' #-------------------------------------------------------------------- lines_of = ( route, handler ) -> #.................................................................. stream = readline.createInterface input: fs.createReadStream route output: process.stdout terminal: false #.................................................................. stream.on 'close', -> handler null, null #.................................................................. stream.on 'error', ( error ) -> handler error #.................................................................. stream.on 'line', ( line ) -> handler null, line 

它工作正常,除非最后一行文件从不报告,除非它被换行符终止。 有没有什么办法来解决这个问题(当然,手动添加换行符)?

你应该使用fs模块来分割文件内容\n字符以确定行结束的位置。