2016-04-12 110 views
0

以下是帶有節點js的'逐行'模板。 如何更改爲支持npm的服務器端流星1.3?流星1.3與npm一行一行

  var LineByLineReader = require('line-by-line'), 
     lr = new LineByLineReader('big_file.txt'); 

     lr.on('error', function (err) { 
     // 'err' contains error object 
      }); 

      lr.on('line', function (line) { 

      }); 
+0

使用Meteor.bindEnvironment在回調替換 '功能'? – user3078524

回答

0
`var future = new Future(); 

    lr = new LineByLineReader('/home/mark/big_file.txt'); 

    console.log("got new line reader"); 

    lr.on('error',Meteor.bindEnvironment(function (err) { 
    // 'err' contains error object 
    })); 

    lr.on('line', Meteor.bindEnvironment(function (line) { 
    // 'line' contains the current line without the trailing newline  character. 

     console.log("got line " + line); 
})); 


    lr.on('end', Meteor.bindEnvironment(function() { 
// All lines are read, file is closed now. 
    console.log("NOW DONE"); 
    future.return("hello joe"); 
})); 


    var requestResults = future.wait(); 

    } 
+0

oops return future.wait(); – user3078524