@serialport/parser-delimiter
Advanced tools
Comparing version 1.0.5 to 2.0.1
@@ -1,3 +0,1 @@ | ||
'use strict' | ||
const Buffer = require('safe-buffer').Buffer | ||
const Transform = require('stream').Transform | ||
@@ -17,4 +15,3 @@ | ||
class DelimiterParser extends Transform { | ||
constructor (options) { | ||
options = options || {} | ||
constructor(options = {}) { | ||
super(options) | ||
@@ -30,3 +27,4 @@ | ||
this.includeDelimiter = options.includeDelimiter !== undefined ? options.includeDelimiter : false | ||
this.includeDelimiter = | ||
options.includeDelimiter !== undefined ? options.includeDelimiter : false | ||
this.delimiter = Buffer.from(options.delimiter) | ||
@@ -36,7 +34,12 @@ this.buffer = Buffer.alloc(0) | ||
_transform (chunk, encoding, cb) { | ||
_transform(chunk, encoding, cb) { | ||
let data = Buffer.concat([this.buffer, chunk]) | ||
let position | ||
while ((position = data.indexOf(this.delimiter)) !== -1) { | ||
this.push(data.slice(0, position + (this.includeDelimiter ? this.delimiter.length : 0))) | ||
this.push( | ||
data.slice( | ||
0, | ||
position + (this.includeDelimiter ? this.delimiter.length : 0) | ||
) | ||
) | ||
data = data.slice(position + this.delimiter.length) | ||
@@ -48,3 +51,3 @@ } | ||
_flush (cb) { | ||
_flush(cb) { | ||
this.push(this.buffer) | ||
@@ -51,0 +54,0 @@ this.buffer = Buffer.alloc(0) |
{ | ||
"name": "@serialport/parser-delimiter", | ||
"main": "delimiter.js", | ||
"version": "1.0.5", | ||
"dependencies": { | ||
"safe-buffer": "^5.1.1" | ||
"version": "2.0.1", | ||
"engines": { | ||
"node": ">=6.0.0" | ||
}, | ||
@@ -14,4 +14,5 @@ "publishConfig": { | ||
"type": "git", | ||
"url": "git://github.com/node-serialport/parsers.git" | ||
} | ||
"url": "git://github.com/node-serialport/node-serialport.git" | ||
}, | ||
"gitHead": "40a06fb71d659940ed5058316b594b9da9957c2f" | ||
} |
@@ -1,1 +0,1 @@ | ||
See our api docs https://node-serialport.github.io/parsers/DelimiterParser.html | ||
See our api docs https://node-serialport.github.io/node-serialport/DelimiterParser.html |
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
3684
0
5
48
- Removedsafe-buffer@^5.1.1
- Removedsafe-buffer@5.2.1(transitive)