mash/node-imagemagick-native — pull request #39 by TimWolla (2014-06-30 13:33:46+00:00)
Title: Async proof of concept

see mash/node-imagemagick-native#23

I modified the `Identify` function to be async. *See this as a proof of concept*. Therefore the pull request breaks backwards compatibility, does not update tests, probably does not match your general code style and what not.

I am not a C(++) programmer and basically made this change by trial and error. If you would give me feedback to improve the code and your wishes (e.g. names for the async functions) I can try to update the other functions as well.

Demo:

```
[timwolla@/d/w/c/node-imagemagick-native (async)]npm install

> imagemagick-native@1.2.1 install /data/workspace/c/node-imagemagick-native
> node-gyp rebuild

make: Entering directory `/data/workspace/c/node-imagemagick-native/build'
CXX(target) Release/obj.target/imagemagick/src/imagemagick.o
../src/imagemagick.cc: In function ‘v8::Handle Convert(const v8::Arguments&)’:
../src/imagemagick.cc:194:40: warning: ‘format’ may be used uninitialized in this function [-Wmaybe-uninitialized]
if ( strcmp( format, "PNG" ) == 0 ) {
^
SOLINK_MODULE(target) Release/obj.target/imagemagick.node
SOLINK_MODULE(target) Release/obj.target/imagemagick.node: Finished
COPY Release/imagemagick.node
make: Leaving directory `/data/workspace/c/node-imagemagick-native/build'
[timwolla@/d/w/c/node-imagemagick-native (async)]cat test.js
imagemagick = require('./build/Release/imagemagick');
imagemagick.identify({
srcData: (require('fs')).readFileSync('test.png'),
debug: 1
}, function (err, data) {
console.log(err, data);
});
[timwolla@/d/w/c/node-imagemagick-native (async)]node test.js
debug: on
ignoreWarnings: 0
original width,height: 1500, 1500
null { width: 1500,
height: 1500,
depth: 8,
format: 'PNG',
exif: { orientation: 0 } }
[timwolla@/d/w/c/node-imagemagick-native (async)]cp test.js test.png
[timwolla@/d/w/c/node-imagemagick-native (async)]node test.js
debug: on
ignoreWarnings: 0
[Error: image.read failed with error: Magick: no decode delegate for this image format `' @ error/blob.c/BlobToImage/364] undefined
```