Socket
Socket
Sign inDemoInstall

stream-lines

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-lines - npm Package Compare versions

Comparing version 1.1.3 to 1.1.5

64

lib/line-stream.js

@@ -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": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc