Comparing version 1.2.0 to 2.0.0
@@ -12,4 +12,9 @@ module.exports = read | ||
, b | ||
, l = buf.length | ||
do { | ||
if(counter >= l) { | ||
read.bytesRead = 0 | ||
return undefined | ||
} | ||
b = buf[counter++] | ||
@@ -16,0 +21,0 @@ res += shift < 28 |
{ | ||
"name": "varint", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "protobuf-style varint bytes - use msb to create integer values of varying sizes", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -41,9 +41,10 @@ # varint | ||
if you are using this to decode buffers from a streaming source it's up to you to make sure that you send 'complete' buffers into `varint.decode`. the maximum number of bytes that varint will need to decode is 8, so all you have to do is make sure you are sending buffers that are at least 8 bytes long from the point at which you know a varint range begins. | ||
If varint is passed a buffer that does not contain a valid end | ||
byte, then `decode` will return undefined, and `decode.bytesRead` | ||
will be set to 0. If you are reading from a streaming source, | ||
it's okay to pass an incomplete buffer into `decode`, detect this | ||
case, and then concatenate the next buffer. | ||
for example, if you are reading buffers from a `fs.createReadStream`, | ||
imagine the first buffer contains one full varint range and half of a second one, and the second buffer contains the second half of the second varint range. in order to be safe across the buffer boundaries you'd just have to make sure the buffer you give to `varint.decode` contains the full varint range (8 bytes), otherwise you'll get an error. | ||
# License | ||
MIT |
14
test.js
@@ -120,4 +120,18 @@ var varint = require('./index') | ||
test('buffer too short', function (assert) { | ||
var value = encode(9812938912312) | ||
var buffer = encode(value) | ||
var l = buffer.length | ||
while(l--) { | ||
var val = decode(buffer.slice(0, l)) | ||
assert.equal(val, undefined) | ||
assert.equal(decode.bytesRead, 0) | ||
} | ||
assert.end() | ||
}) | ||
function randint(range) { | ||
return Math.floor(Math.random() * range) | ||
} |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
8745
8
227
50
1