Browse Source

make PNGStream a real Stream (so stream.pipe(dest) works)

Signed-off-by: Tj Holowaychuk <tj@vision-media.ca>
v1.x
Marcello Bastea-Forte 14 years ago
committed by Tj Holowaychuk
parent
commit
cb6c4483e9
  1. 7
      lib/pngstream.js

7
lib/pngstream.js

@ -9,7 +9,7 @@
* Module dependencies.
*/
var EventEmitter = require('events').EventEmitter;
var Stream = require('stream').Stream;
/**
* Initialize a `PNGStream` with the given `canvas`.
@ -41,16 +41,19 @@ var PNGStream = module.exports = function PNGStream(canvas, sync) {
: 'streamPNG';
this.sync = sync;
this.canvas = canvas;
this.readable = true;
// TODO: implement async
if ('streamPNG' == method) method = 'streamPNGSync';
process.nextTick(function(){
canvas[method](function(err, chunk, len){
if (err) {
self.emit('error', err);
self.readable = false;
} else if (len) {
self.emit('data', chunk, len);
} else {
self.emit('end');
self.readable = false;
}
});
});
@ -60,4 +63,4 @@ var PNGStream = module.exports = function PNGStream(canvas, sync) {
* Inherit from `EventEmitter`.
*/
PNGStream.prototype.__proto__ = EventEmitter.prototype;
PNGStream.prototype.__proto__ = Stream.prototype;
Loading…
Cancel
Save