diff --git a/lib/command.js b/lib/command.js index 2ff464fe..0a2aea9f 100644 --- a/lib/command.js +++ b/lib/command.js @@ -36,7 +36,7 @@ module.exports = function (proto) { } } - function streamToUnemptyBuffer(stream, callback) { + function streamToUnemptyBuffer(stream, callback, errorstream) { var done = false var buffers = [] @@ -44,6 +44,17 @@ module.exports = function (proto) { buffers.push(data) }) + if (errorstream) { + errorstream.on('data', function (error) { + if (error) { + debug('Error stream data: ' + error.toString()); + done = true; + buffers = null; + callback(error.toString()); + } + }); + } + stream.on('end', function () { var result, err; if (done) @@ -159,10 +170,10 @@ module.exports = function (proto) { throw new Error('gm().toBuffer() expects a callback.'); } - return this.stream(format, function (err, stdout) { + return this.stream(format, function (err, stdout, stderr) { if (err) return callback(err); - streamToUnemptyBuffer(stdout, callback); + streamToUnemptyBuffer(stdout, callback, stderr); }) }