Permalink
Browse files

Use setEncoding.

  • Loading branch information...
stephank committed Jan 31, 2012
1 parent a1a6f55 commit ebbb3d2cd43d953a4734d11dc2e76433cbe0b6af
Showing with 4 additions and 5 deletions.
  1. +4 −5 lib/carrier.js
View
@@ -12,11 +12,10 @@ function Carrier(reader, listener, encoding) {
var line = '';
+ reader.setEncoding(encoding || 'utf-8');
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") {
+ var lines = data.split("\n");
+ if (data.charAt(data.length - 1) == "\n") {
// get rid of last "" after last "\n"
lines.pop(1);
}
@@ -28,7 +27,7 @@ function Carrier(reader, listener, encoding) {
var emit = true;
if (index == lines.length - 1) {
// processing last line
- if (decoded.charAt(decoded.length - 1) != "\n") {
+ if (data.charAt(data.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;

0 comments on commit ebbb3d2

Please sign in to comment.