diff options
Diffstat (limited to 'tools/eslint/node_modules/parse5/lib/serializer/stream.js')
-rw-r--r-- | tools/eslint/node_modules/parse5/lib/serializer/stream.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tools/eslint/node_modules/parse5/lib/serializer/stream.js b/tools/eslint/node_modules/parse5/lib/serializer/stream.js new file mode 100644 index 00000000000..304b28d24b5 --- /dev/null +++ b/tools/eslint/node_modules/parse5/lib/serializer/stream.js @@ -0,0 +1,49 @@ +'use strict'; + +var ReadableStream = require('stream').Readable, + inherits = require('util').inherits, + Serializer = require('./index'); + +/** + * Streaming AST node to an HTML serializer. + * A [readable stream]{@link https://nodejs.org/api/stream.html#stream_class_stream_readable}. + * @class SerializerStream + * @memberof parse5 + * @instance + * @extends stream.Readable + * @param {ASTNode} node - Node to serialize. + * @param {SerializerOptions} [options] - Serialization options. + * @example + * var parse5 = require('parse5'); + * var fs = require('fs'); + * + * var file = fs.createWriteStream('/home/index.html'); + * + * // Serializes the parsed document to HTML and writes it to the file. + * var document = parse5.parse('<body>Who is John Galt?</body>'); + * var serializer = new parse5.SerializerStream(document); + * + * serializer.pipe(file); + */ +var SerializerStream = module.exports = function (node, options) { + ReadableStream.call(this); + + this.serializer = new Serializer(node, options); + + Object.defineProperty(this.serializer, 'html', { + //NOTE: To make `+=` concat operator work properly we define + //getter which always returns empty string + get: function () { + return ''; + }, + set: this.push.bind(this) + }); +}; + +inherits(SerializerStream, ReadableStream); + +//Readable stream implementation +SerializerStream.prototype._read = function () { + this.serializer.serialize(); + this.push(null); +}; |