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 0.0.2 to 0.0.3

decode.js

48

index.js
module.exports = varint
varint.encode = encode
varint.encode = require('./encode.js');
var EE = require('events').EventEmitter
, MSB = 0x80
, REST = 0x7F
, MSBALL = ~REST
, Decoder = require('./decode.js')
function varint() {
var ee = new EE
, dec = new Decoder
ee.write = write
ee.accum = []
return ee
}
function encode(num, out, offset) {
out = out || []
offset = offset || 0
while(num & MSBALL) {
out[offset++] = (num & 0xFF) | MSB
num >>>= 7
dec.ondata = function (item) {
ee.emit("data", item)
}
out[offset] = num
return out
}
function write(byte) {
var msb = byte & MSB
, accum = this.accum
, len
, out
accum[accum.length] = byte & REST
if(msb) {
return
ee.write = function (item) {
dec.write(item);
}
len = accum.length
out = 0
return ee
}
for(var i = 0; i < len; ++i) {
out |= accum[i] << (7 * i)
}
accum.length = 0
this.emit('data', out)
return
}
{
"name": "varint",
"version": "0.0.2",
"version": "0.0.3",
"description": "use msb to create integer values of varying sizes",

@@ -5,0 +5,0 @@ "main": "index.js",

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