blob: daf39c3b6e37739fb89f6cc1df45a6c9df78d1eb [file] [log] [blame]
Yang Guo4fd355c2019-09-19 10:59:03 +02001var WritableStream = require('stream').Writable
2var inherits = require('util').inherits
3
4module.exports = BrowserStdout
5
6
7inherits(BrowserStdout, WritableStream)
8
9function BrowserStdout(opts) {
10 if (!(this instanceof BrowserStdout)) return new BrowserStdout(opts)
11
12 opts = opts || {}
13 WritableStream.call(this, opts)
14 this.label = (opts.label !== undefined) ? opts.label : 'stdout'
15}
16
17BrowserStdout.prototype._write = function(chunks, encoding, cb) {
18 var output = chunks.toString ? chunks.toString() : chunks
19 if (this.label === false) {
20 console.log(output)
21 } else {
22 console.log(this.label+':', output)
23 }
24 process.nextTick(cb)
25}