-
-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drop split and stream-combiner to make the default stream not drop ne…
…wlines in ie<9
- Loading branch information
James Halliday
committed
Dec 17, 2013
1 parent
9b8a771
commit ea56255
Showing
2 changed files
with
15 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
var through = require('through'); | ||
var combine = require('stream-combiner'); | ||
var split = require('split'); | ||
|
||
module.exports = function () { | ||
var stream = combine(split(), through(write)); | ||
return stream; | ||
var line = ''; | ||
return through(write, flush); | ||
|
||
function write (line) { | ||
function write (buf) { | ||
for (var i = 0; i < buf.length; i++) { | ||
var c = typeof buf === 'string' | ||
? buf.charAt(i) | ||
: String.fromCharCode(buf[i]) | ||
; | ||
if (c === '\n') flush(); | ||
else line += c; | ||
} | ||
} | ||
|
||
function flush () { | ||
try { console.log(line); } | ||
catch (e) { stream.emit('error', e) } | ||
line = ''; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters