length-prefixed-stream
Advanced tools
Comparing version 1.4.0 to 1.5.0
@@ -12,4 +12,10 @@ var varint = require('varint') | ||
this._limit = opts && opts.limit || 0 | ||
this._allowEmpty = !!(opts && opts.allowEmpty) | ||
this._prefix = new Buffer(this._limit ? varint.encodingLength(this._limit) : 100) | ||
this._ptr = 0 | ||
if (this._allowEmpty) { | ||
this._readableState.highWaterMark = 16 | ||
this._readableState.objectMode = true | ||
} | ||
} | ||
@@ -33,2 +39,3 @@ | ||
if (this._limit && this._missing > this._limit) return this._prefixError(data) | ||
if (!this._missing && this._allowEmpty) this._push(Buffer(0)) | ||
this._ptr = 0 | ||
@@ -35,0 +42,0 @@ return offset + 1 |
{ | ||
"name": "length-prefixed-stream", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "Streaming length prefixed buffers", | ||
@@ -13,2 +13,3 @@ "main": "index.js", | ||
"from2": "^2.1.0", | ||
"standard": "^6.0.7", | ||
"tape": "^2.14.0", | ||
@@ -18,3 +19,3 @@ "through2": "^0.6.1" | ||
"scripts": { | ||
"test": "tape test.js" | ||
"test": "standard && tape test.js" | ||
}, | ||
@@ -21,0 +22,0 @@ "repository": { |
20
test.js
@@ -248,1 +248,21 @@ var tape = require('tape') | ||
}) | ||
tape('allow empty', function (t) { | ||
var d = lpstream.decode() | ||
d.on('data', function () { | ||
t.fail('should not emit empty buffers') | ||
}) | ||
d.on('end', function () { | ||
d = lpstream.decode({allowEmpty: true}) | ||
d.on('data', function (data) { | ||
t.same(data, Buffer(0), 'empty buffer') | ||
t.end() | ||
}) | ||
d.write(Buffer([0])) | ||
d.end() | ||
}) | ||
d.write(Buffer([0])) | ||
d.end() | ||
}) |
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
11708
316
5