<commit_before>events= require("events")
fs =require('fs')

environment = process.env['NODE_ENV'] || 'development'

class Tail extends events.EventEmitter

  readBlock:()=>
    if @queue.length >= 1
      block=@queue[0]
      if block.end > block.start
        stream = fs.createReadStream(@filename, {start:block.start, end:block.end-1, encoding:"utf-8"})
        stream.on 'error',(error) =>
          console.log("Tail error:#{error}")
          @emit('error', error)
        stream.on 'end',=>
          @queue.shift()
          @internalDispatcher.emit("next") if @queue.length >= 1
        stream.on 'data', (data) =>
          @buffer += data
          parts = @buffer.split(@separator)
          @buffer = parts.pop()
          @emit("line", chunk) for chunk in parts

  constructor:(@filename, @separator='\n') ->    
    @buffer = ''
    @internalDispatcher = new events.EventEmitter()
    @queue = []
             
    @internalDispatcher.on 'next',=>
      @readBlock()
    
    fs.watchFile @filename, (curr, prev) =>
      if curr.size > prev.size
        @queue.push({start:prev.size, end:curr.size})  <commit_msg>added fsWatchOptions as optional parameter to be able to set custom interval<commit_after>events= require("events")
fs =require('fs')

environment = process.env['NODE_ENV'] || 'development'

class Tail extends events.EventEmitter

  readBlock:()=>
    if @queue.length >= 1
      block=@queue[0]
      if block.end > block.start
        stream = fs.createReadStream(@filename, {start:block.start, end:block.end-1, encoding:"utf-8"})
        stream.on 'error',(error) =>
          console.log("Tail error:#{error}")
          @emit('error', error)
        stream.on 'end',=>
          @queue.shift()
          @internalDispatcher.emit("next") if @queue.length >= 1
        stream.on 'data', (data) =>
          @buffer += data
          parts = @buffer.split(@separator)
          @buffer = parts.pop()
          @emit("line", chunk) for chunk in parts

  constructor:(@filename, @separator='\n', @fsWatchOptions = {}) ->    
    @buffer = ''
    @internalDispatcher = new events.EventEmitter()
    @queue = []
             
    @internalDispatcher.on 'next',=>
      @readBlock()
    
    fs.watchFile @filename, @fsWatchOptions, (curr, prev) =>
      if curr.size > prev.size
        @queue.push({start:prev.size, end:curr.size})  
{'fraction_non_alphanumeric': 0.16130397967823878, 'fraction_numerical': 0.004233700254022015, 'mean_word_length': 2.6131498470948014, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2581977', 'n_tokens_mistral': 723, 'n_tokens_neox': 709, 'n_words': 155}