Skip to content

Commit

Permalink
Release v0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
pgte committed Nov 22, 2010
1 parent d12d4f9 commit f7a410f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/carrier.js
Expand Up @@ -10,29 +10,33 @@ function Carrier(reader, listener, encoding) {
self.addListener('line', listener);
}

line = '';
var line = '';

reader.on('data', function(data) {
var decoded = data.toString(encoding);
//console.log(decoded);
var lines = decoded.split("\n");
if (decoded.charAt(decoded.length - 1) == "\n") {
// get rid of last "" after last "\n"
lines.pop(1);
}

if (lines.length > 0) {
//console.log('Have ' + lines.length + " lines\n");
lines.forEach(function(one_line, index) {
line += one_line;
var emit = true;
if (index == lines.length - 1) {
// processing last line
if (decoded.charAt(decoded.length - 1) != "\n") {
// if it was not terminated by "\n" then the last line was not finished; we just buffer it.
//console.log('last one does not have \n, not emitting');
emit = false;
}
}
if (emit) {
line = line.replace("\r", '');
//console.log('emiting ' + line + "\n");
self.emit('line', line);
line = '';
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{ "name" : "carrier"
, "description" : "Evented stream line reader for node.js"
, "version" : "0.0.3"
, "version" : "0.0.4"
, "homepage" : "http://github.com/pgte/carrier"
, "author" : "Pedro Teixeira <pedro.teixeira@gmail.com> (http://www.metaduck.com)"
, "contributors" :
Expand Down

0 comments on commit f7a410f

Please sign in to comment.