|
|
@ -8,6 +8,7 @@ var spawn = require('child_process').spawn; |
|
|
|
var utils = require('./utils'); |
|
|
|
var utils = require('./utils'); |
|
|
|
var debug = require('debug')('gm'); |
|
|
|
var debug = require('debug')('gm'); |
|
|
|
var series = require('array-series'); |
|
|
|
var series = require('array-series'); |
|
|
|
|
|
|
|
var through = require('through'); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Error messaging. |
|
|
|
* Error messaging. |
|
|
@ -89,17 +90,27 @@ module.exports = function (proto) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Execute the command and return stdin and stderr ReadableStreams providing the image data. |
|
|
|
* Execute the command and return stdin and stderr |
|
|
|
|
|
|
|
* ReadableStreams providing the image data. |
|
|
|
|
|
|
|
* If no callback is passed, a "through" stream will be returned, |
|
|
|
|
|
|
|
* and stdout will be piped through, otherwise the error will be passed. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param {Function} callback |
|
|
|
* @param {String} format (optional) |
|
|
|
* @return {Object} gm |
|
|
|
* @param {Function} callback (optional) |
|
|
|
|
|
|
|
* @return {Stream} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
proto.stream = function stream (format, callback) { |
|
|
|
proto.stream = function stream (format, callback) { |
|
|
|
if (!callback) callback = format, format = null; |
|
|
|
if (!callback) callback = format, format = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var throughStream; |
|
|
|
|
|
|
|
|
|
|
|
if ("function" !== typeof callback) { |
|
|
|
if ("function" !== typeof callback) { |
|
|
|
throw new TypeError("gm().stream() expects a callback function") |
|
|
|
throughStream = through() |
|
|
|
|
|
|
|
callback = function (err, stdout, stderr) { |
|
|
|
|
|
|
|
if (err) throughStream.emit('error', err); |
|
|
|
|
|
|
|
else stdout.pipe(throughStream); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (format) { |
|
|
|
if (format) { |
|
|
@ -112,6 +123,8 @@ module.exports = function (proto) { |
|
|
|
if (err) return callback(err); |
|
|
|
if (err) return callback(err); |
|
|
|
return self._spawn(self.args(), false, callback); |
|
|
|
return self._spawn(self.args(), false, callback); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return throughStream |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|