Skip to content

Commit

Permalink
write sync to stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-Esch authored and James Halliday committed May 17, 2014
1 parent a9f5302 commit 14ab9d1
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/default_stream.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
var through = require('through');
var fs = require('fs');

module.exports = function () {
var line = '';
var stream = through(write, flush);
return stream;

function write (buf) {
for (var i = 0; i < buf.length; i++) {
var c = typeof buf === 'string'
Expand All @@ -15,9 +16,9 @@ module.exports = function () {
else line += c;
}
}

function flush () {
try { console.log(line); }
try { fs.writeSync(1, line + '\n'); }
catch (e) { stream.emit('error', e) }
line = '';
}
Expand Down

0 comments on commit 14ab9d1

Please sign in to comment.