Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,25 @@ module.exports = function (proto) {
}
}

function streamToUnemptyBuffer(stream, callback) {
function streamToUnemptyBuffer(stream, callback, errorstream) {
var done = false
var buffers = []

stream.on('data', function (data) {
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)
Expand Down Expand Up @@ -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);
})
}

Expand Down