Created
March 11, 2014 18:41
-
-
Save bhurlow/9492279 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var util = require('util'); | |
var Transform = require('stream').Transform; | |
util.inherits(SizeStream, Transform); | |
function SizeStream() { | |
if (!(this instanceof SizeStream)) | |
return new SizeStream() | |
Transform.call(this) | |
} | |
SizeStream.prototype._transform = function(chunk, encoding, done) { | |
try { | |
var s = pngsize(chunk) | |
if (s) { | |
this.emit('size', s) | |
done() | |
} | |
} | |
catch(e) { | |
this.emit('error', new Error('problem with the whole sizing thing')); | |
return; | |
} | |
// send data to next stream | |
this.push('downstream \n') | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment