stream-lines
Advanced tools
Comparing version 1.1.3 to 1.1.5
@@ -29,33 +29,45 @@ var through = require('through3') | ||
if(this.buffer && this.buffer.length) { | ||
chunk = Buffer.concat( | ||
[this.buffer, chunk], this.buffer.length + chunk.length); | ||
} | ||
if(Buffer.isBuffer(chunk)) { | ||
// end with line feed, safe to split the lot | ||
if(chunk[chunk.length - 1] === LF) { | ||
str = chunk.toString(this.encoding); | ||
}else{ | ||
// reverse search for line feed | ||
while((b = chunk[i]) !== undefined) { | ||
if(b === LF) { | ||
// get what we can split now | ||
str = chunk.toString(this.encoding, 0, i); | ||
// stash the remainder for the next transform or flush | ||
this.buffer = chunk.slice(i); | ||
break; | ||
if(this.buffer && this.buffer.length) { | ||
chunk = Buffer.concat( | ||
[this.buffer, chunk], this.buffer.length + chunk.length); | ||
} | ||
// end with line feed, safe to split the lot | ||
if(chunk[chunk.length - 1] === LF) { | ||
str = chunk.toString(this.encoding); | ||
}else{ | ||
// reverse search for line feed | ||
while((b = chunk[i]) !== undefined) { | ||
if(b === LF) { | ||
// get what we can split now | ||
str = chunk.toString(this.encoding, 0, i); | ||
// stash the remainder for the next transform or flush | ||
this.buffer = chunk.slice(i); | ||
break; | ||
} | ||
i--; | ||
} | ||
i--; | ||
} | ||
// no newline found, possibly very long line | ||
if(!str) { | ||
this.buffer = !this.buffer | ||
? chunk | ||
: Buffer.concat([this.buffer, chunk], this.buffer.length + chunk.length); | ||
return cb(); | ||
} | ||
}else if(typeof chunk === 'string') { | ||
str = chunk; | ||
}else{ | ||
// force objectMode false instead? | ||
return cb(new Error('line stream accepts buffers or strings')); | ||
} | ||
// no newline found, possibly very long line | ||
if(!str) { | ||
this.buffer = !this.buffer | ||
? chunk | ||
: Buffer.concat([this.buffer, chunk], this.buffer.length + chunk.length); | ||
return cb(); | ||
//console.dir(str); | ||
if(typeof str === 'string') { | ||
lines = str.split(this.eol); | ||
} | ||
lines = str.split(this.eol); | ||
if(this.body) { | ||
@@ -74,3 +86,3 @@ this.body = this.body.concat(lines); | ||
if(this.buffer) { | ||
lines = [this.buffer.toString(this.encoding)]; | ||
lines = [this.buffer.toString(this.encoding).replace(/^\r?\n/, '')]; | ||
if(this.body) { | ||
@@ -77,0 +89,0 @@ this.body = this.body.concat(lines); |
{ | ||
"name": "stream-lines", | ||
"description": "Line transform stream, reads bytes writes arrays of lines.", | ||
"version": "1.1.3", | ||
"version": "1.1.5", | ||
"author": "muji <noop@xpm.io>", | ||
@@ -31,3 +31,4 @@ "repository": { | ||
"readme": "mdp --force -v", | ||
"test": "NODE_ENV=test istanbul cover --root ./lib _mocha -- test/spec" | ||
"test": "NODE_ENV=test mocha -- test/spec", | ||
"cover": "NODE_ENV=test istanbul cover --root ./lib _mocha -- test/spec" | ||
}, | ||
@@ -34,0 +35,0 @@ "mdp": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5914
93