Merge pull request #142 from jonathanong/remove-buffer-stream

remove bufferStream option
master
Jonathan Ong 11 years ago
commit bf2dcc1c03
  1. 16
      lib/command.js
  2. 2
      lib/convenience/autoOrient.js
  3. 5
      lib/getters.js
  4. 46
      lib/utils.js
  5. 13
      test/streamInGetter.js
  6. 1
      test/utils.js

@ -200,24 +200,12 @@ module.exports = function (proto) {
proc.stdin.end();
} else if (self.sourceStream) {
if (!self.sourceStream.readable && !self.bufferStream) {
err = new Error("gm().stream() or gm().write() with a non-readable " +
"stream. Pass \"{bufferStream: true}\" to identify() " +
"or getter (size, format, etc...)");
if (!self.sourceStream.readable) {
err = new Error("gm().stream() or gm().write() with a non-readable stream.");
return cb(self, err);
}
self.sourceStream.pipe(proc.stdin);
// resume any buffered events from a previous identify operation
if (self._buffer) {
self._buffer.resume();
// if {bufferStream: true} was passed to an identify operation,
// we buffer the input stream events so we can use them again
} else if (self.bufferStream) {
self._buffer = utils.buffer(self.sourceStream);
}
}
// for _exec operations (identify() mostly), we also

@ -18,7 +18,7 @@ module.exports = function (proto) {
proto.autoOrient = function autoOrient () {
this.preprocessor(function (callback) {
this.orientation({bufferStream: true}, function (err, orientation) {
this.orientation(function (err, orientation) {
if (err) return callback(err);
var transforms = exifTransforms[orientation.toLowerCase()];

@ -49,8 +49,6 @@ module.exports = function (gm) {
return self;
}
self.bufferStream = !! opts.bufferStream;
self.on(getter, createListener(callback));
if (val.verbose) {
@ -112,7 +110,6 @@ module.exports = function (gm) {
}
self._identifyState = IDENTIFYING;
self.bufferStream = !! opts.bufferStream;
var args = makeArgs(self, { verbose: true });
@ -128,7 +125,7 @@ module.exports = function (gm) {
self.emit('identify', err, self.data, stdout, stderr, cmd);
return;
}
self.data.path = self.source;
self.emit('identify', null, self.data);

@ -11,52 +11,6 @@ exports.escape = function escape (arg) {
return '"' + String(arg).trim().replace(/"/g, '\\"') + '"';
}
/**
* Buffer `data` and `end` events from the given stream `obj`.
*
* @param {Stream} obj
* @api public
*/
// __Attribution:__ Taken from node-http-proxy's stream buffer implementation
// https://github.com/nodejitsu/node-http-proxy/blob/9f05e6c567/lib/node-http-proxy.js#L223-256
// https://github.com/nodejitsu/node-http-proxy/blob/9f05e6c567/LICENSE
exports.buffer = function (obj) {
var events = []
, onData
, onEnd;
obj.on('data', onData = function (data, encoding) {
events.push(['data', data, encoding]);
});
obj.on('end', onEnd = function (data, encoding) {
events.push(['end', data, encoding]);
});
return {
end: function () {
obj.removeListener('data', onData);
obj.removeListener('end', onEnd);
}
, destroy: function () {
this.end();
this.resume = function () {
console.error("Cannot resume buffer after destroying it.");
};
onData = onEnd = events = obj = null;
}
, resume: function () {
this.end();
for (var i = 0, len = events.length; i < len; ++i) {
obj.emit.apply(obj, events[i]);
}
}
};
};
exports.argsToArray = function (args) {
var arr = [];

@ -6,9 +6,16 @@ module.exports = function (_, dir, finish, gm) {
if (!gm.integration)
return finish();
gm(fs.createReadStream(dir + '/original.jpg'), "original.jpg")
.size({bufferStream: true}, function (err, size) {
this.write(dir + '/streamInGetter.png', function streamInGetter (err){
var imageStream = fs.createReadStream(dir + '/original.jpg')
var buffers = []
imageStream.on('data', function (chunk) {
buffers.push(chunk)
})
gm(imageStream)
.size(function (err, size) {
gm(Buffer.concat(buffers)).write(dir + '/streamInGetter.png', function streamInGetter (err){
finish(err);
});
});

@ -3,7 +3,6 @@ var assert = require('assert')
module.exports = function (_, dir, finish, gm) {
assert.equal('function', typeof gm.utils.buffer);
assert.equal('function', typeof gm.utils.escape);
finish();

Loading…
Cancel
Save