Skip to content
This repository
Browse code

Added BufferedStream.coffee, utility class for buffering text streams.

  • Loading branch information...
commit 4aa82cbbf9b9b9cea723a101eab6dc8608ece996 1 parent ec054f6
Jacob Beard authored

Showing 1 changed file with 20 additions and 0 deletions. Show diff stats Hide diff stats

  1. +20 0 src/main/coffeescript/util/BufferedStream.coffee
20 src/main/coffeescript/util/BufferedStream.coffee
... ... @@ -0,0 +1,20 @@
  1 +define ['events'],(events) ->
  2 +
  3 + class BufferedEventEmitter extends events.EventEmitter
  4 +
  5 + constructor : (emitter,ev='data',encoding='utf8',delimiter='\n') ->
  6 + emitter.setEncoding encoding
  7 +
  8 + data = ""
  9 +
  10 + emitter.on ev,(s) =>
  11 + console.log "received string: #{s}"
  12 + data += s
  13 +
  14 + lineOrientedData = data.split delimiter
  15 + lines = lineOrientedData[0...-1]
  16 + data = lineOrientedData.pop()
  17 +
  18 + console.log "lines",lines
  19 +
  20 + @emit "line",line for line in lines

0 comments on commit 4aa82cb

Please sign in to comment.
Something went wrong with that request. Please try again.