index.js 649 B

12345678910111213141516171819202122232425
  1. var WritableStream = require('stream').Writable
  2. var inherits = require('util').inherits
  3. module.exports = BrowserStdout
  4. inherits(BrowserStdout, WritableStream)
  5. function BrowserStdout(opts) {
  6. if (!(this instanceof BrowserStdout)) return new BrowserStdout(opts)
  7. opts = opts || {}
  8. WritableStream.call(this, opts)
  9. this.label = (opts.label !== undefined) ? opts.label : 'stdout'
  10. }
  11. BrowserStdout.prototype._write = function(chunks, encoding, cb) {
  12. var output = chunks.toString ? chunks.toString() : chunks
  13. if (this.label === false) {
  14. console.log(output)
  15. } else {
  16. console.log(this.label+':', output)
  17. }
  18. process.nextTick(cb)
  19. }