index.js 414 B

1234567891011121314151617181920
  1. var util = require('util')
  2. var Transform = require('stream').Transform
  3. util.inherits(Counter, Transform)
  4. module.exports = Counter
  5. function Counter(options) {
  6. if (!(this instanceof Counter))
  7. return new Counter(options)
  8. Transform.call(this, options)
  9. this.length = 0
  10. }
  11. Counter.prototype._transform = function (chunk, encoding, callback) {
  12. this.length += chunk.length
  13. this.push(chunk)
  14. callback()
  15. }