Commit 21db8f2e authored by Leo Iannacone's avatar Leo Iannacone

extends Tail in pure coffee

parent 37c4f95e
"use strict"
fs = require("fs") fs = require("fs")
Tail = require("tail").Tail Tail = require("tail").Tail
Tail::watchEvent = (e) ->
_this = this
if e is "change"
fs.stat @filename, (err, stats) ->
if err
_this.emit "error", err
return
_this.pos = stats.size if stats.size < _this.pos
if stats.size > _this.pos
_this.queue.push
start: _this.pos
end: stats.size
_this.pos = stats.size class MyTail extends Tail
_this.internalDispatcher.emit "next" if _this.queue.length is 1
else if e is "rename" watchEvent: (e) ->
if e is 'change'
stats = fs.statSync(@filename)
@pos = stats.size if stats.size < @pos #scenario where texts is not appended but it's actually a w+
if stats.size > @pos
@queue.push({start: @pos, end: stats.size})
@pos = stats.size
@internalDispatcher.emit("next") if @queue.length is 1
else if e is 'rename'
@unwatch() @unwatch()
_this.emit "error", "File " + @filename + " deleted." @emit "error", "File " + @filename + " deleted."
return
Tail::close = -> close: () ->
@unwatch() @unwatch()
return return
module.exports = Tail module.exports = MyTail
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment