我需要强制关闭一个readline文件......在第11行!我需要优化!!但是没有处理调用this.emit("close");
var readline = require('readline');
var stream = require('stream');
function get_line3(filename, number, callback) {
var instream = fs.createReadStream(filename);
var outstream = new stream;
var rl = readline.createInterface(instream, outstream);
var contp = 0;
var data = "";
rl.on("line", function(line) {
console.log(contp);
if (contp==number) this.emit("pause", line);
contp++;
});
rl.on("pause", function(line) {
// do some work here
console.log("doing some work");
console.log(line);
data = line;
this.emit("resume");
});
rl.on("resume", function(line) {
this.emit("close"); // NOT WORK !!!
});
rl.on("close", function() {
// do something on finish here
callback(null, data);
});
}