StreamValues.js 784 B

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. const StreamBase = require('./StreamBase');
  3. const withParser = require('../utils/withParser');
  4. class StreamValues extends StreamBase {
  5. static make(options) {
  6. return new StreamValues(options);
  7. }
  8. static withParser(options) {
  9. return withParser(StreamValues.make, Object.assign({}, options, {jsonStreaming: true}));
  10. }
  11. constructor(options) {
  12. super(options);
  13. this._counter = 0;
  14. this._level = 0;
  15. }
  16. _push(discard) {
  17. if (discard) {
  18. ++this._counter;
  19. } else {
  20. this.push({key: this._counter++, value: this._assembler.current});
  21. }
  22. this._assembler.current = this._assembler.key = null;
  23. }
  24. }
  25. StreamValues.streamValues = StreamValues.make;
  26. StreamValues.make.Constructor = StreamValues;
  27. module.exports = StreamValues;