lucagrulla / node-tail

The zero dependency Node.js module for tailing a file
https://www.lucagrulla.com/node-tail/
MIT License
467 stars 76 forks source link

if nLines > count of separators, no lines are displayed #138

Closed pward123 closed 3 years ago

pward123 commented 3 years ago

At the following line, when nLines >= tokens.length, the existing contents of the file are not emitted as line events.

https://github.com/lucagrulla/node-tail/blob/6a771ef65b0dbdeba41f8b97bcf41f437d45db9b/src/tail.js#L62

For example, if I start a tail on a file with 17 existing lines, pass nLines: 50 and dropLastToken = 1, the regex ends up as: (?:[^\r\n]*[\r]{0,1}\n){-34}

Since it doesn't make sense to look for a negative number of matches, regex instead looks for -34 literally. The result is zero matches.