1'use strict'; 2 3const { Readable } = require('stream'); 4const Serializer = require('parse5/lib/serializer'); 5 6class SerializerStream extends Readable { 7 constructor(node, options) { 8 super({ encoding: 'utf8' }); 9 10 this.serializer = new Serializer(node, options); 11 12 Object.defineProperty(this.serializer, 'html', { 13 //NOTE: To make `+=` concat operator work properly we define 14 //getter which always returns empty string 15 get: function() { 16 return ''; 17 }, 18 set: this.push.bind(this) 19 }); 20 } 21 22 //Readable stream implementation 23 _read() { 24 this.serializer.serialize(); 25 this.push(null); 26 } 27} 28 29module.exports = SerializerStream; 30