- var readline = require('readline');
- var fs = require('fs');
- var os = require('os');
-
- var fReadName = './1.log';
- var fWriteName = './1.readline.log';
- var fRead = fs.createReadStream(fReadName);
- var fWrite = fs.createWriteStream(fWriteName);
-
- var enableWriteIndex = true;
- fRead.on('end', ()=>{
- console.log('end');
- enableWriteIndex = false;
- });
-
- var objReadline = readline.createInterface({
- input: fRead,
- output: fWrite,
- terminal: true
- });
-
-
- var index = 1;
- fWrite.write('line' + index.toString() +':');
- objReadline.on('line', (line)=>{
- console.log(index, line);
- if (enableWriteIndex) {
-
-
- index ++;
- var tmp = 'line' + index.toString() + ':';
- fWrite.write(tmp);
- }
- });
-
-
-
- objReadline.on('close', ()=>{
- console.log('readline close...');
- });
posted @
2017-11-15 15:23
世界,太精彩
阅读(
1473)
评论()
编辑
收藏
举报