forked from elad/node-imagemagick-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (35 loc) · 1.02 KB
/
index.js
File metadata and controls
43 lines (35 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module.exports = require(__dirname + '/build/Release/imagemagick.node');
// Idea for stream conversions from
// http://codewinds.com/blog/2013-08-20-nodejs-transform-streams.html
var stream = require('stream');
var util = require('util');
// node v0.10+ use native Transform, else polyfill
var Transform = stream.Transform ||
require('readable-stream').Transform;
function Convert(options) {
// allow use without new
if (!(this instanceof Convert)) {
return new Convert(options);
}
this._options = options;
this._bufs = [];
// init Transform
Transform.call(this, options);
}
util.inherits(Convert, Transform);
Convert.prototype._transform = function (chunk, enc, done) {
this._bufs.push(chunk);
done();
};
Convert.prototype._flush = function(done) {
this._options.srcData = Buffer.concat(this._bufs);
var self = this;
module.exports.convert(this._options,function(err,data){
if(err) {
return done(err);
}
self.push(data);
done();
});
}
module.exports.streams = { convert : Convert };