Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #21 from xenomuta/master

Added CR+LF terminated lines support for DOS/Windows text encoding
  • Loading branch information...
commit 1ccf46c61154c22a5d11012fa34984155ed274cd 2 parents 83afb5e + 48698e0
@pkrumins pkrumins authored
Showing with 9 additions and 2 deletions.
  1. +9 −2 lazy.js
View
11 lazy.js
@@ -178,11 +178,12 @@ function Lazy (em, opts) {
// Streams that use this should emit strings or buffers only
self.__defineGetter__('lines', function () {
return self.bucket([], function (chunkArray, chunk) {
- var newline = '\n'.charCodeAt(0), lastNewLineIndex = 0;
+ var newline = ['\r'.charCodeAt(0), '\n'.charCodeAt(0)], lastNewLineIndex = 0;
if (typeof chunk === 'string') chunk = new Buffer(chunk);
for (var i = 0; i < chunk.length; i++) {
- if (chunk[i] === newline) {
+ // Match line separator characters
+ if (newline.indexOf(chunk[i]) !== -1) {
// If we have content from the current chunk to append to our buffers, do it.
if(i>0){
if(i === lastNewLineIndex){
@@ -191,8 +192,14 @@ function Lazy (em, opts) {
chunkArray.push(chunk.slice(lastNewLineIndex, i));
}
+ // Skip second separator byte on \r\n terminated lines ( yeah, stupid DOS / Windows, I know... )
+ if ((i + 1 < chunk.length) && (chunk[i] === newline[0]) && (chunk[i + 1] === newline[1])) {
+ i++;
+ }
+
// Wrap all our buffers and emit it.
this(mergeBuffers(chunkArray));
+
lastNewLineIndex = i + 1;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.