DataLengthProbe.js 829 B

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. var utils = require("../utils");
  3. var GenericWorker = require("./GenericWorker");
  4. /**
  5. * A worker which calculate the total length of the data flowing through.
  6. * @constructor
  7. * @param {String} propName the name used to expose the length
  8. */
  9. function DataLengthProbe(propName) {
  10. GenericWorker.call(this, "DataLengthProbe for " + propName);
  11. this.propName = propName;
  12. this.withStreamInfo(propName, 0);
  13. }
  14. utils.inherits(DataLengthProbe, GenericWorker);
  15. /**
  16. * @see GenericWorker.processChunk
  17. */
  18. DataLengthProbe.prototype.processChunk = function (chunk) {
  19. if(chunk) {
  20. var length = this.streamInfo[this.propName] || 0;
  21. this.streamInfo[this.propName] = length + chunk.data.length;
  22. }
  23. GenericWorker.prototype.processChunk.call(this, chunk);
  24. };
  25. module.exports = DataLengthProbe;