You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

nginxparser

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nginxparser - npm Package Compare versions

Comparing version
1.1.0
to
1.2.0
+42
-23
index.js

@@ -40,15 +40,17 @@ var fs = require('fs')

* @param {Object} options (optional)
* @param {Function} callback
* @param {Function} iterator - called for each line
* @param {Function} callback (optional) - called at the end
*/
Parser.prototype.read = function (path, options, callback) {
Parser.prototype.read = function (path, options, iterator, callback) {
if (typeof options === 'function') {
callback = options;
callback = iterator;
iterator = options;
}
if (!path || path === '-') {
return this.stdin(callback);
return this.stdin(iterator, callback);
} else if (options.tail) {
return this.tail(path, callback);
return this.tail(path, iterator, callback);
}
return this.stream(fs.createReadStream(path), callback);
return this.stream(fs.createReadStream(path), iterator, callback);
};

@@ -60,8 +62,9 @@

* @param {String} path
* @param {Function} callback
* @param {Function} iterator - called for each line
* @param {Function} callback (optional) - called at the end
*/
Parser.prototype.tail = function (path, callback) {
Parser.prototype.tail = function (path, iterator, callback) {
var stream = spawn('tail', [ '-F', '-c', '+0', path]).stdout;
return this.stream(stream, callback);
return this.stream(stream, iterator, callback);
};

@@ -72,7 +75,8 @@

*
* @param {Function} callback
* @param {Function} iterator - called for each line
* @param {Function} callback (optional) - called at the end
*/
Parser.prototype.stdin = function (callback) {
return this.stream(process.stdin, callback);
Parser.prototype.stdin = function (iterator, callback) {
return this.stream(process.stdin, iterator, callback);
};

@@ -84,7 +88,8 @@

* @param {ReadableStream} stream
* @param {Function} callback
* @param {Function} iterator - called for each line
* @param {Function} callback (optional) - called at the end
*/
Parser.prototype.stream = function (stream, callback) {
var self = this, overflow = new Buffer(0);
Parser.prototype.stream = function (stream, iterator, callback) {
var self = this, overflow = new Buffer(0), complete = false;
stream.on('data', function (data) {

@@ -94,3 +99,3 @@ var buffer = buffertools.concat(overflow, data), newline = 0;

if (buffer[i] === 10) {
self.parseLine(buffer.slice(newline, i), callback);
self.parseLine(buffer.slice(newline, i), iterator);
newline = i + 1;

@@ -101,10 +106,24 @@ }

});
if (callback) {
stream.on('error', function (err) {
if (complete) return;
complete = true;
callback(err);
});
}
stream.on('end', function () {
if (overflow.length) {
self.parseLine(overflow, callback);
self.parseLine(overflow, iterator);
}
if (complete) return;
complete = true;
if (callback) {
callback();
}
});
process.nextTick(function () {
stream.resume();
});
if (stream.resume) {
process.nextTick(function () {
stream.resume();
});
}
return stream;

@@ -117,6 +136,6 @@ };

* @param {Buffer|String} line
* @param {Function} callback
* @param {Function} iterator
*/
Parser.prototype.parseLine = function (line, callback) {
Parser.prototype.parseLine = function (line, iterator) {
var match = line.toString().match(this.parser);

@@ -182,3 +201,3 @@ if (!match) {

callback(row);
iterator(row);
};

@@ -185,0 +204,0 @@

{ "name" : "nginxparser",
"description" : "Parse Nginx log files",
"version" : "1.1.0",
"version" : "1.2.0",
"homepage" : "http://github.com/chriso/nginx_parser",

@@ -5,0 +5,0 @@ "author" : "Chris O'Hara <cohara87@gmail.com>",

@@ -14,3 +14,3 @@ **nginx_parser** parse nginx log files in node.js

```javascript
var NginxParser = require('nginx_parser');
var NginxParser = require('nginxparser');

@@ -22,2 +22,5 @@ var parser = new NginxParser('$remote_addr - $remote_user [$time_local] '

console.log(row);
}, function (err) {
if (err) throw err;
console.log('Done!')
});

@@ -24,0 +27,0 @@ ```

@@ -18,2 +18,4 @@ var NginxParser = require('./')

console.log(row);
}, function (err) {
console.log('Done!')
});

@@ -20,0 +22,0 @@