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

extends Tail in pure coffee

parent 37c4f95e
"use strict"
fs = require("fs")
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
_this.internalDispatcher.emit "next" if _this.queue.length is 1
class MyTail extends Tail
else if e is "rename"
@unwatch()
_this.emit "error", "File " + @filename + " deleted."
return
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()
@emit "error", "File " + @filename + " deleted."
Tail::close = ->
@unwatch()
return
close: () ->
@unwatch()
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