Basic version

pull/21/head
Maciej Winnicki 2013-08-12 20:47:35 +02:00
parent c7fbe1ac19
commit bab90d4b60
5 changed files with 61 additions and 3 deletions

View File

@ -23,6 +23,8 @@
"browser": true,
"globals": {
"io": false
"io": false,
"describe": false,
"it": false
}
}

View File

@ -1,4 +1,7 @@
lint:
@./node_modules/.bin/jshint .
.PHONY: lint
test:
@./node_modules/.bin/mocha --reporter spec
.PHONY: lint test

25
lib/tail.js Normal file
View File

@ -0,0 +1,25 @@
(function () {
'use strict';
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var spawn = require('child_process').spawn;
var Tail = function (path) {
EventEmitter.call(this);
var self = this;
var tail = spawn('tail', ['-F'].concat(path));
tail.stdout.on('data', function (data) {
var line = data.toString('utf-8');
self.emit('line', line);
});
};
util.inherits(Tail, EventEmitter);
module.exports = function (path) {
return new Tail(path);
};
})();

View File

@ -15,7 +15,10 @@
"cookie": "0.1.0"
},
"devDependencies": {
"jshint": "~2.1.10"
"jshint": "~2.3.0",
"should": "~2.0.2",
"mocha": "~1.13.0",
"temp": "~0.6.0"
},
"repository": {
"type": "git",

25
test/tail.js Normal file
View File

@ -0,0 +1,25 @@
(function () {
'use strict';
require('should');
var fs = require('fs');
var tail = require('../lib/tail');
var temp = require('temp');
describe('tail', function () {
temp.track();
it('should call event line if new line appear in file', function (done) {
temp.open('test', function (err, info) {
tail(info.path).on('line', function (line) {
line.should.equal('testline');
done();
});
fs.write(info.fd, 'testline');
fs.close(info.fd);
});
});
});
})();