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

tail

Package Overview
Dependencies
Maintainers
0
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 0.0.4 to 0.1.0

4

package.json

@@ -6,3 +6,3 @@ {

"description": "tail a file in node",
"version": "0.0.4",
"version": "0.1.0",
"repository": {

@@ -14,3 +14,3 @@ "type": "git",

"engines": {
"node": "v0.4.8"
"node": "0.4 || 0.5"
},

@@ -17,0 +17,0 @@ "dependencies": {},

var Tail, events, fs;
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }

@@ -9,3 +9,3 @@ function ctor() { this.constructor = child; }

return child;
}, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
};
events = require("events");

@@ -15,39 +15,58 @@ fs = require('fs');

__extends(Tail, events.EventEmitter);
Tail.prototype.readBlock = function() {
var block, stream;
block = this.queue[0];
if (block.end > block.start) {
stream = fs.createReadStream(this.filename, {
start: block.start,
end: block.end - 1,
encoding: "utf-8"
});
stream.on('error', __bind(function(error) {
return this.emit('error', error);
}, this));
stream.on('end', __bind(function() {
return this.emit('end');
}, this));
stream.on('close', __bind(function() {
this.queue.shift();
if (this.queue.length >= 1) {
this.internalDispatcher("next");
}
return this.emit('close');
}, this));
stream.on('fd', __bind(function(fd) {
return this.emit('fd', fd);
}, this));
return stream.on('data', __bind(function(data) {
var chunk, parts, _i, _len, _results;
this.buffer += data;
parts = this.buffer.split(this.separator);
this.buffer = parts.pop();
_results = [];
for (_i = 0, _len = parts.length; _i < _len; _i++) {
chunk = parts[_i];
_results.push(this.emit("data", chunk));
}
return _results;
}, this));
}
};
function Tail(filename, separator) {
var buffer;
this.filename = filename;
this.separator = separator || '\n';
buffer = '';
this.separator = separator != null ? separator : '\n';
this.readBlock = __bind(this.readBlock, this);
this.buffer = '';
this.internalDispatcher = new events.EventEmitter();
this.queue = [];
this.internalDispatcher.on('next', __bind(function() {
return this.readBlock();
}, this));
fs.watchFile(this.filename, __bind(function(curr, prev) {
var stream;
if (curr.size > prev.size) {
stream = fs.createReadStream(this.filename, {
start: prev.size,
end: curr.size - 1,
encoding: "utf-8"
});
stream.on('error', __bind(function(error) {
return this.emit('error', error);
}, this));
stream.on('end', __bind(function() {
return this.emit('end');
}, this));
stream.on('close', __bind(function() {
return this.emit('close');
}, this));
stream.on('fd', __bind(function(fd) {
return this.emit('fd', fd);
}, this));
return stream.on('data', __bind(function(data) {
var chunk, parts, _i, _len, _results;
buffer += data;
parts = buffer.split(this.separator);
buffer = parts.pop();
_results = [];
for (_i = 0, _len = parts.length; _i < _len; _i++) {
chunk = parts[_i];
_results.push(this.emit("data", chunk));
}
return _results;
}, this));
this.queue.push({
start: prev.size,
end: curr.size
});
if (this.queue.length === 1) {
return this.internalDispatcher.emit("next");
}

@@ -54,0 +73,0 @@ }, this));

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