aheckmann/gm — pull request #22 by kainosnoema (2011-11-29 05:01:08+00:00)
Title: Added support for Streams (in/out)

Of all the GraphicsMagick modules for Node, gm seems the most complete/stable, but we were sorely missing support for streaming processing. These commits add support for streaming image data both in and out of gm, while keeping the original API intact and adhering as closely as possible to the existing coding style. I did have to upgrade the Node requirement to v0.4.2, but since NPM requires >v0.4, and v0.6 is the current stable release, I felt it was acceptable at this point.

All the existing tests are passing, and I've added three tests to cover the very basics of handling streams. I didn't update History.md or bump the version, leaving that to you if/when you decide to merge. If so, gm will be able to handle a true streaming image processing workflow, enabling a lot of really interesting implementations.

Example usage of the new stream API:

```` js
// can provide either a file path or a ReadableStream
// (from a local file or incoming network request)
var readableStream = fs.createReadableStream('/path/to/my/img.jpg');
gm(readableStream, 'img.jpg')
.write('/path/to/reformat.png', function (err) {
if (!err) console.log('done');
});

// can also stream output to a ReadableStream
// (can be piped to a local file or remote server)
gm('/path/to/my/img.jpg')
.stream(function (err, stdout, stderr) {
var writableStream = fs.createWritableStream('/path/to/my/reformat.png');
stdout.pipe(writableStream);
});

// combine the two for true streaming image processing
var readableStream = fs.createReadableStream('/path/to/my/img.jpg');
gm(readableStream, 'img.jpg')
.stream(function (err, stdout, stderr) {
var writableStream = fs.createWritableStream('/path/to/my/reformat.png');
stdout.pipe(writableStream);
});
````