Skip to content

Instantly share code, notes, and snippets.

@bhurlow
Created March 11, 2014 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhurlow/9492279 to your computer and use it in GitHub Desktop.
Save bhurlow/9492279 to your computer and use it in GitHub Desktop.
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