Document BufferedProcess and BufferedNodeProcess

This commit is contained in:
Matt Colyer
2013-08-22 15:27:01 -07:00
parent f47fdd0ae1
commit d5c2878d53
2 changed files with 22 additions and 4 deletions

View File

@@ -1,10 +1,10 @@
BufferedProcess = require 'buffered-process'
path = require 'path'
# Like BufferedProcess, but accepts a node script instead of an executable,
# on Unix which allows running scripts and executables, this seems unnecessary,
# but on Windows we have to separate scripts from executables since it doesn't
# support shebang strings.
# Private: Like BufferedProcess, but accepts a node script instead of an
# executable, on Unix which allows running scripts and executables, this seems
# unnecessary, but on Windows we have to separate scripts from executables since
# it doesn't support shebang strings.
module.exports =
class BufferedNodeProcess extends BufferedProcess
constructor: ({command, args, options, stdout, stderr, exit}) ->

View File

@@ -2,11 +2,19 @@ ChildProcess = require 'child_process'
path = require 'path'
_ = require 'underscore'
# Private: A wrapper which provides buffering for ChildProcess
module.exports =
class BufferedProcess
process: null
killed: false
# options -
# command: The command to execute.
# args: The arguments for the given command.
# options: The options to pass to ChildProcess.
# stdout: The callback to receive stdout data.
# stderr: The callback to receive stderr data.
# exit: The callback to receive exit status.
constructor: ({command, args, options, stdout, stderr, exit}={}) ->
options ?= {}
@process = ChildProcess.spawn(command, args, options)
@@ -39,6 +47,13 @@ class BufferedProcess
processExited = true
triggerExitCallback()
# Private: Helper method to pass data line by line.
#
# stream - The Stream to read from.
# onLines - The callback to call with each line of data.
# onDone - The callback to call when the stream has closed.
#
# Returns nothing.
bufferStream: (stream, onLines, onDone) ->
stream.setEncoding('utf8')
buffered = ''
@@ -56,6 +71,9 @@ class BufferedProcess
onLines(buffered) if buffered.length > 0
onDone()
# Public: Terminates the process.
#
# Returns nothing.
kill: ->
@killed = true
@process.kill()