Encode and decode EBML variable sized integers.
npm install ebml-varint
The interfaces exposes the two methods
encode(num, [buffer], [offset]) and
decode(buffer, [start], [end]) for converting a number from and to a buffer. Additionally the method
encodingLength(num) returns the number of bytes required to encode a given integer, and
decodingLength(buffer, [start], [end]) returns the number of bytes the integer occupies in the buffer.
var varint = ;var buffer = varint; // Returns a buffer with two bytes [0x41, 0x00]var num = varint; // Returns the number 256varint; // Returns twovarint; // Also returns two
2^53 - 1, the encode method will throw an error if trying to encode an integer bigger than that.