Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

varint

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

varint - npm Package Compare versions

Comparing version 1.2.0 to 2.0.0

bench.js

5

decode.js

@@ -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

2

package.json
{
"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

@@ -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)
}
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