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

vlq-buffer

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vlq-buffer

A simple set of functions for converting between integer and VLQ buffer values

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

vlq-buffer

npm npm

A simple set of functions for converting between integer and VLQ buffer values

Installation

$ npm install --save vlq-buffer

Reference vlq-buffer

var vlqBuffer = require('vlq-buffer');

Usage

int2VLQBuffer

This method converts an integer to a Buffer containing the VLQ representation of that integer.


var myInt = 2097151;
var bufferValue = vlqBuffer.int2VLQBuffer(myInt);

// bufferValue == <Buffer ff ff 7f>

vlqBuffer2Int

This method converts a Buffer containing a VLQ value to an integer.


var myVLQValue = new Buffer([0x81, 0x80, 0x00]);
var intValue = vlqBuffer.vlqBuffer2Int(myVLQValue);

// intValue == 16384

isVLQLastByte

This method returns true if the given integer's binary value starts with zero, indicating tne end of the VLQ value. This is useful for identifying the final byte in a VLQ value when reading binary data.


var vlqStartIndex = readIndex; // start reading a vlq value and the current read index
var currentByte = bufferData.readUInt8(readIndex);
while (!vlqBuffer.isVLQLastByte(currentByte)) {
        if (++readIndex >= bufferData.length) throw 'EOF error'; // EOF, no vql end found
    currentByte = bufferData.readUInt8(readIndex);
}
var vlqValueBytes = bufferData.slice(vlqStartIndex, ++readIndex);
var intValue = vlq.vlqBuffer2Int(vlqValueBytes);

Keywords

FAQs

Package last updated on 08 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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