Index: lib/byline.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lib/byline.js	(revision da4a1cc63b0f7e569d80bf8a368a757e867b3924)
+++ lib/byline.js	(revision )
@@ -68,6 +68,7 @@
   this._readableState.objectMode = true;
   this._lineBuffer = [];
   this._keepEmptyLines = options.keepEmptyLines || false;
+  this._lastChunkEndedWithCR = false;
 
   // take the source's encoding if we don't have one
   this.on('pipe', function(src) {
@@ -85,6 +86,8 @@
   // decode binary chunks as UTF-8
   encoding = encoding || 'utf8';
   
+  //console.log(chunk.length);
+  
   if (Buffer.isBuffer(chunk)) {
     if (encoding == 'buffer') {
       chunk = chunk.toString(); // utf8
@@ -98,11 +101,17 @@
   
   var lines = chunk.split(/\r\n|\r|\n/g);
   
+  // don't split CRLF which spans chunks
+  if (this._lastChunkEndedWithCR && chunk[0] == '\n') {
+    lines.shift();
+  }
+  
   if (this._lineBuffer.length > 0) {
     this._lineBuffer[this._lineBuffer.length - 1] += lines[0];
     lines.shift();
   }
-  
+
+  this._lastChunkEndedWithCR = chunk[chunk.length - 1] == '\r';
   this._lineBuffer = this._lineBuffer.concat(lines);
   this._pushBuffer(encoding, 1, done);
 };
Index: test/CRLF.txt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- test/CRLF.txt	(revision )
+++ test/CRLF.txt	(revision )
@@ -0,0 +1,2 @@
[encoded data, 65636 characters]
\ No newline at end of file
Index: test/tests.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- test/tests.js	(revision da4a1cc63b0f7e569d80bf8a368a757e867b3924)
+++ test/tests.js	(revision )
@@ -60,7 +60,23 @@
       done();
     });
   });
-   
+
+  it('should not split a CRLF which spans two chunks', function(done) {
+    var input = fs.createReadStream('test/CRLF.txt');
+    var lineStream = byline(input, { keepEmptyLines: true });
+    lineStream.setEncoding('utf8');
+
+    var lines = [];
+    lineStream.on('data', function(line) {
+      lines.push(line);
+    });
+
+    lineStream.on('end', function() {
+      assert.equal(2, lines.length);
+      done();
+    });
+  });
+   
   it('should read a large file', function(done) {
     readFile('test/rfc.txt', done);
   }); 
@@ -110,6 +126,9 @@
   it('should work with old-style streams', function(done) {
     var stream = byline(request.get('http://www.google.com'));
     stream.on('data',function (data) {
+    });
+    stream.on('end',function () {
+      done();
     });
   });
 
\ No newline at end of file
