Fork of github:chrisdickinson/varint with BigInt support
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
Max Ogden 50ae23c9e9 also return length from decode 11 years ago
README.md also return length from decode 11 years ago
decode.js also return length from decode 11 years ago
encode.js switch out the accumulator reader for a faster buffer reader 11 years ago
index.js switch out the accumulator reader for a faster buffer reader 11 years ago
package.json switch out the accumulator reader for a faster buffer reader 11 years ago
test.js also return length from decode 11 years ago

README.md

varint

encode whole numbers to an array of protobuf-style varint bytes and also decode them.

var varint = require('varint')

var bytes = varint.encode(300) // === [0xAC, 0x02]
varint.decode(bytes) // [300, 2]

api

varint = require('varint')

varint.encode(num[, output=[], offset=0]) -> array

encodes num into either the array given by offset or a new array at offset and returns that array filled with integers.

varint.decode(data[, offset=0]) -> [number, length]

decodes data, which can be either a buffer or array of integers, from position offset or default 0 and returns an array containing [number, length] where number is the original integer and length is the amount of bytes that were consumed in order to decode the number

License

MIT