0

I am trying to read files 1 line at a time using this doc

https://nodejs.org/api/readline.html

from the answer here Read a file one line at a time in node.js?

proposed by Dan.

The problem is, it doesn't specify how to call a function when the file is fully read from.

Does anyone know?

Thanks

Community
  • 1
  • 1
omega
  • 40,311
  • 81
  • 251
  • 474

1 Answers1

0

In the comments of Dan's answer, someone gives the answer to your question:

lineReader.on('close', callback);
Community
  • 1
  • 1
Joost Vunderink
  • 1,178
  • 6
  • 14
  • Also is it possible to get the max line number? This is to show progress. – omega Dec 26 '15 at 22:41
  • http://stackoverflow.com/questions/12453057/node-js-count-the-number-of-lines-in-a-file – Joost Vunderink Dec 26 '15 at 22:56
  • This is a way to get it by reading all the lines. I wanted a way to get it before even reading it. – omega Dec 26 '15 at 22:57
  • So you want to know how many lines are in a file, without reading the file? That's clearly not possible. If you want to show progress, you could get the *size* of the file at the start (that's a very fast operation) and keep track of the total number of characters you have read so far (counting the length of each line read). – Joost Vunderink Dec 26 '15 at 23:01
  • For the current line string, is it each character=4bytes? And do I have to add 4bytes for the new line character? – omega Dec 26 '15 at 23:07