Comparing version 2.2.0 to 2.2.1
@@ -13,3 +13,3 @@ let events = require(`events`) | ||
class Tail extends events.EventEmitter { | ||
constructor(filename, options = {}) { | ||
@@ -59,14 +59,21 @@ super(); | ||
flag: 'r', | ||
encoding:this.encoding | ||
}); | ||
encoding: this.encoding | ||
}); | ||
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 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(); | ||
} else { | ||
startingCursor = this.latestPosition() ; | ||
startingCursor = this.latestPosition(); | ||
} | ||
if (startingCursor === undefined) throw new Error("Tail can't initialize."); | ||
const flush = fromBeginning || (this.nLines != undefined); | ||
this.watch(startingCursor, flush); | ||
try { | ||
this.watch(startingCursor, flush); | ||
} catch (err) { | ||
this.logger.error(`watch for ${this.filename} failed: ${err}`); | ||
this.emit("error", `watch for ${this.filename} failed: ${err}`); | ||
} | ||
} | ||
@@ -124,3 +131,3 @@ | ||
} else if (p > this.currentCursorPos) { | ||
this.queue.push({ start: this.currentCursorPos, end: p}); | ||
this.queue.push({ start: this.currentCursorPos, end: p }); | ||
this.currentCursorPos = p | ||
@@ -143,15 +150,8 @@ if (this.queue.length == 1) { | ||
try { | ||
if (!this.useWatchFile && fs.watch) { | ||
this.logger.info(`watch strategy: watch`); | ||
this.watcher = fs.watch(this.filename, this.fsWatchOptions, (e, filename) => { this.watchEvent(e, filename); }); | ||
} else { | ||
this.logger.info(`watch strategy: watchFile`); | ||
fs.watchFile(this.filename, this.fsWatchOptions, (curr, prev) => { this.watchFileEvent(curr, prev) }); | ||
} | ||
} catch (err) { | ||
this.logger.error(`watch for ${this.filename} failed: ${err}`); | ||
this.emit("error", `watch for ${this.filename} failed: ${err}`); | ||
return | ||
if (!this.useWatchFile && fs.watch) { | ||
this.logger.info(`watch strategy: watch`); | ||
this.watcher = fs.watch(this.filename, this.fsWatchOptions, (e, filename) => { this.watchEvent(e, filename); }); | ||
} else { | ||
this.logger.info(`watch strategy: watchFile`); | ||
fs.watchFile(this.filename, this.fsWatchOptions, (curr, prev) => { this.watchFileEvent(curr, prev) }); | ||
} | ||
@@ -173,4 +173,9 @@ } | ||
this.filename = path.join(this.absPath, filename); | ||
this.rewatchId = setTimeout((() => { | ||
this.watch(this.currentCursorPos); | ||
this.rewatchId = setTimeout((() => { | ||
try { | ||
this.watch(this.currentCursorPos); | ||
} catch (ex) { | ||
this.logger.error(`'rename' event for ${this.filename}. File not available anymore.`); | ||
this.emit("error", ex); | ||
} | ||
}), 1000); | ||
@@ -177,0 +182,0 @@ } else { |
@@ -17,3 +17,3 @@ { | ||
], | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"homepage": "https://www.lucagrulla.com/node-tail", | ||
@@ -36,3 +36,2 @@ "repository": { | ||
"license": "MIT", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
@@ -39,0 +38,0 @@ "chai": "4.x", |
@@ -11,4 +11,7 @@ # Tail | ||
Author: [Luca Grulla](https://www.lucagrulla.com) - [www.lucagrulla.com](https://www.lucagrulla.com) | ||
Made with ❤️ by [Luca Grulla](https://www.lucagrulla.com) | ||
1. TOC | ||
{:toc} | ||
## Installation | ||
@@ -62,3 +65,3 @@ | ||
new Tail('missingFile.txt') | ||
} catch ex { | ||
} catch (ex) { | ||
console.log(ex) | ||
@@ -108,5 +111,6 @@ } | ||
``` | ||
The error emitted is either the underline exception or a descriptive string. | ||
## How to contribute | ||
Node Tail code repo is [here](https://github.com/lucagrulla/node-tail/) | ||
Tail is written in ES6. Pull Requests are welcome. | ||
@@ -116,4 +120,4 @@ | ||
Tail was born as part of a data firehose. Read about it [here](https://www.lucagrulla.com/posts/building-a-firehose-with-nodejs/). | ||
Tail original version was written in [CoffeeScript](https://coffeescript.org/). Since December 2020 it's pure ES6. | ||
Tail was born as part of a data firehose. Read more about that project [here](https://www.lucagrulla.com/posts/building-a-firehose-with-nodejs/). | ||
Tail originally was written in [CoffeeScript](https://coffeescript.org/). Since December 2020 it's pure ES6. | ||
@@ -120,0 +124,0 @@ ## License |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16372
6
200
123