Converts spawn to a ReadStream, buffers the error and emits it
Make child process spawn behave like a read stream (buffer the error, don't emit end if error emitted).
npm install spawn-to-readstream
var toReadStream = require'spawn-to-readstream'spawn = require'child_process'spawn;toReadStreamspawn'ls' '-lah'on'error'throw err;on'end'console.log'~~~ DONE ~~~';on'data'console.log'ls data :::' datatoString;;
Limiting the output of the steam
var toReadStream = require'../index'spawn = require'child_process'spawnlimit buf;buf = 0;limit = 100 * 1024; // 100 Kb// Note that it's a 'soft' limit, meaning the data you// receive might be > 100 Kb, because the child process// was stopped after receiving more than <LIMIT> bytestoReadStreamspawn'cat' '/dev/urandom' limiton'error'throw err;on'end'console.log'done, ' + buf + ' bytes received';if isLimitedconsole.log'child process was cut';on'data'buf += datalength;;