From cb6c4483e9312c68e95bf3004f3c05e384c21cc9 Mon Sep 17 00:00:00 2001 From: Marcello Bastea-Forte Date: Sat, 9 Apr 2011 12:02:06 -0400 Subject: [PATCH] make PNGStream a real Stream (so stream.pipe(dest) works) Signed-off-by: Tj Holowaychuk --- lib/pngstream.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/pngstream.js b/lib/pngstream.js index 2f3ecf6..cb5461d 100644 --- a/lib/pngstream.js +++ b/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; \ No newline at end of file +PNGStream.prototype.__proto__ = Stream.prototype; \ No newline at end of file