Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tail

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tail - npm Package Compare versions

Comparing version 1.4.0 to 2.0.0

121

lib/tail.js

@@ -61,7 +61,8 @@ // Generated by CoffeeScript 2.3.1

constructor(filename, options = {}) {
var pos;
var fromBeginning;
super(filename, options);
this.readBlock = this.readBlock.bind(this);
this.change = this.change.bind(this);
this.filename = filename;
({separator: this.separator = /[\r]{0,1}\n/, fsWatchOptions: this.fsWatchOptions = {}, fromBeginning: this.fromBeginning = false, follow: this.follow = true, logger: this.logger, useWatchFile: this.useWatchFile = false, flushAtEOF: this.flushAtEOF = false, encoding: this.encoding = "utf-8"} = options);
({separator: this.separator = /[\r]{0,1}\n/, fsWatchOptions: this.fsWatchOptions = {}, fromBeginning = false, follow: this.follow = true, logger: this.logger, useWatchFile: this.useWatchFile = false, flushAtEOF: this.flushAtEOF = false, encoding: this.encoding = "utf-8"} = options);
if (this.logger) {

@@ -79,9 +80,34 @@ this.logger.info("Tail starting...");

});
if (this.fromBeginning) {
pos = 0;
this.watch(fromBeginning);
}
change(filename) {
var err, stats;
boundMethodCheck(this, Tail);
try {
stats = fs.statSync(filename);
} catch (error1) {
err = error1;
if (this.logger) {
this.logger.error(`'${e}' event for ${filename}. ${err}`);
}
this.emit("error", `'${e}' event for ${filename}. ${err}`);
return;
}
this.watch(pos);
if (stats.size < this.pos) { //scenario where texts is not appended but it's actually a w+
this.pos = stats.size;
}
if (stats.size > this.pos) {
this.queue.push({
start: this.pos,
end: stats.size
});
this.pos = stats.size;
if (this.queue.length === 1) {
return this.internalDispatcher.emit("next");
}
}
}
watch(pos) {
watch(fromBeginning) {
var err, stats;

@@ -91,2 +117,7 @@ if (this.isWatching) {

}
if (this.logger) {
this.logger.info(`filesystem.watch present? ${fs.watch !== void 0}`);
this.logger.info(`useWatchFile: ${this.useWatchFile}`);
this.logger.info(`fromBeginning: ${fromBeginning}`);
}
this.isWatching = true;

@@ -103,6 +134,5 @@ try {

}
this.pos = pos != null ? pos : stats.size;
if (this.logger) {
this.logger.info(`filesystem.watch present? ${fs.watch !== void 0}`);
this.logger.info(`useWatchFile: ${this.useWatchFile}`);
this.pos = fromBeginning ? 0 : stats.size;
if (this.pos === 0) {
this.change(this.filename);
}

@@ -126,51 +156,24 @@ if (!this.useWatchFile && fs.watch) {

watchEvent(e, filename) {
var err, stats;
if (e === 'change') {
try {
stats = fs.statSync(this.filename);
} catch (error1) {
err = error1;
rename(filename) {
//MacOS sometimes throws a rename event for no reason.
//Different platforms might behave differently.
//see https://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener
//filename might not be present.
//https://nodejs.org/api/fs.html#fs_filename_argument
//Better solution would be check inode but it will require a timeout and
// a sync file read.
if (filename === void 0 || filename !== this.filename) {
this.unwatch();
if (this.follow) {
return setTimeout((() => {
return this.watch();
}), 1000);
} else {
if (this.logger) {
this.logger.error(`'${e}' event for ${this.filename}. ${err}`);
this.logger.error(`'rename' event for ${this.filename}. File not available.`);
}
this.emit("error", `'${e}' event for ${this.filename}. ${err}`);
return;
return this.emit("error", `'rename' event for ${this.filename}. File not available.`);
}
if (stats.size < this.pos) { //scenario where texts is not appended but it's actually a w+
this.pos = stats.size;
}
if (stats.size > this.pos) {
this.queue.push({
start: this.pos,
end: stats.size
});
this.pos = stats.size;
if (this.queue.length === 1) {
return this.internalDispatcher.emit("next");
}
}
} else if (e === 'rename') {
//MacOS sometimes throws a rename event for no reason.
//Different platforms might behave differently.
//see https://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener
//filename might not be present.
//https://nodejs.org/api/fs.html#fs_filename_argument
//Better solution would be check inode but it will require a timeout and
// a sync file read.
if (filename === void 0 || filename !== this.filename) {
this.unwatch();
if (this.follow) {
return setTimeout((() => {
return this.watch();
}), 1000);
} else {
if (this.logger) {
this.logger.error(`'rename' event for ${this.filename}. File not available.`);
}
return this.emit("error", `'rename' event for ${this.filename}. File not available.`);
}
} else {
} else {
}
}

@@ -180,2 +183,10 @@ }

// @logger.info("rename event but same filename")
watchEvent(e, evtFilename) {
if (e === 'change') {
return this.change(this.filename);
} else if (e === 'rename') {
return this.rename(evtFilename);
}
}
watchFileEvent(curr, prev) {

@@ -182,0 +193,0 @@ if (curr.size > prev.size) {

@@ -17,3 +17,3 @@ {

],
"version": "1.4.0",
"version": "2.0.0",
"homepage": "https://www.lucagrulla.com/node-tail",

@@ -26,3 +26,3 @@ "repository": {

"engines": {
"node": ">= 0.4.0"
"node": ">= 6.0.0"
},

@@ -29,0 +29,0 @@ "scripts": {

@@ -18,3 +18,3 @@ # Tail

## Use:
## Use

@@ -48,4 +48,5 @@ ```javascript

## Configuration
The only mandatory parameter is the path to the file to tail.
The only mandatory parameter is the path to the file to tail.
```javascript

@@ -63,3 +64,3 @@ var fileToTail = "/path/to/fileToTail.txt";

## Available parameters
### Constructor parameters

@@ -92,3 +93,5 @@ * `separator`: the line separator token (default: `/[\r]{0,1}\n/` to handle linux/mac (9+)/windows). Pass null if your file is binary there's no line separator.

```javascript
function(exception){}
function(exception){
console.error(exception);
}
```

@@ -108,2 +111,2 @@

MIT. Please see License file for more details.
MIT. Please see [License](https://github.com/lucagrulla/node-tail/blob/master/LICENSE) file for more details.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc