title: Efficiently read file line-by-line in node
body: <p>I have already learned that <a href="https://www.npmjs.com/package/readline" rel="nofollow">readline</a> can be used to read the file line by line, e.g.</p>
  
  <pre><code>readline
      .createInterface({input: fs.createReadStream('xxx')})
      .on('line', (line) =&gt; { apply_regexp_on_line })
      .on('close', () =&gt; { report_all_regexps });
  </code></pre>
  
  <p>However, this is pretty slow, since I compared the performance of <code>grep</code> and JavaScript regexp, and the latter has better performance on the regexps I tested. (see <a href="https://github.com/xis19/regexp_benchmark" rel="nofollow">benchmark</a>) So I think I have to blame the node async readline.</p>
  
  <p>In my situation, I do not care async at all, I just need to exploit the fast regexp from JavaScript to process very large log files (typically 1-2GB, sometimes up to 10GB). What is the best way of doing this? My only concern is speed.</p>
  
  <p>Bonus points: some of the log files are gzipped, so I need to uncompress them. If someone can recommend me a fast line-by-line reader for both plain text and gzipped text exists, I would be really appreciated.</p>