serializer_stream.js 760 B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. var ReadableStream = require('stream').Readable,
  3. inherits = require('util').inherits,
  4. Serializer = require('./index');
  5. var SerializerStream = module.exports = function (node, options) {
  6. ReadableStream.call(this);
  7. this.serializer = new Serializer(node, options);
  8. Object.defineProperty(this.serializer, 'html', {
  9. //NOTE: To make `+=` concat operator work properly we define
  10. //getter which always returns empty string
  11. get: function () {
  12. return '';
  13. },
  14. set: this.push.bind(this)
  15. });
  16. };
  17. inherits(SerializerStream, ReadableStream);
  18. //Readable stream implementation
  19. SerializerStream.prototype._read = function () {
  20. this.serializer.serialize();
  21. this.push(null);
  22. };