Comparing version 2.2.3 to 2.2.4
@@ -61,5 +61,10 @@ let events = require(`events`) | ||
const tokens = data.split(this.separator); | ||
const dropLastToken = (tokens[tokens.length - 1] === '') ? 1 : 0;//if the file end with empty line ignore line NL | ||
const match = data.match(new RegExp(`(?:[^\r\n]*[\r]{0,1}\n){${tokens.length - this.nLines - dropLastToken}}`)); | ||
startingCursor = (match && match.length) ? Buffer.byteLength(match[0], this.encoding) : this.latestPosition(); | ||
const dropLastToken = (tokens[tokens.length - 1] === '') ? 1 : 0;//if the file ends with empty line ignore line NL | ||
if (tokens.length - this.nLines - dropLastToken <= 0) { | ||
//nLines is bigger than avaiable tokens: tail from the begin | ||
startingCursor = 0; | ||
} else { | ||
const match = data.match(new RegExp(`(?:[^\r\n]*[\r]{0,1}\n){${tokens.length - this.nLines - dropLastToken}}`)); | ||
startingCursor = (match && match.length) ? Buffer.byteLength(match[0], this.encoding) : this.latestPosition(); | ||
} | ||
} else { | ||
@@ -188,6 +193,11 @@ startingCursor = this.latestPosition(); | ||
watchEvent(e, evtFilename) { | ||
if (e === 'change') { | ||
this.change(); | ||
} else if (e === 'rename') { | ||
this.rename(evtFilename); | ||
try { | ||
if (e === 'change') { | ||
this.change(); | ||
} else if (e === 'rename') { | ||
this.rename(evtFilename); | ||
} | ||
} catch (err) { | ||
this.logger.error(`watchEvent for ${this.filename} failed: ${err}`); | ||
this.emit("error", `watchEvent for ${this.filename} failed: ${err}`); | ||
} | ||
@@ -194,0 +204,0 @@ } |
@@ -17,3 +17,3 @@ { | ||
], | ||
"version": "2.2.3", | ||
"version": "2.2.4", | ||
"homepage": "https://www.lucagrulla.com/node-tail", | ||
@@ -38,5 +38,5 @@ "repository": { | ||
"chai": "4.x", | ||
"mocha": "8.x", | ||
"mocha": "9.x", | ||
"nyc": "^15.1.0" | ||
} | ||
} | ||
} |
16989
210