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.
 
Chris Dickinson f75a1659aa 0.0.3 11 years ago
README.md add README 11 years ago
decode.js Change decode to use prototype instead of closure 11 years ago
encode.js Make encode and decode accessable standalone 11 years ago
index.js Change decode to use prototype instead of closure 11 years ago
package.json 0.0.3 11 years ago
test.js add more tests 11 years ago

README.md

varint

decode protobuf-style varint bytes and emit whole integers when enough have been accumulated that a number can be constructed; also encode whole numbers to an array of varint style bytes.

var varint = require('varint')

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

vi.once('data', function(num) {
  console.log('got', num)
})

vi.write(bytes[0])
vi.write(bytes[1]) // "got 300"

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.

vi = varint() -> EventEmitter

return a new varint instance.

vi.write(byte) -> undefined

write a byte to the varint. if the byte is "final" (i.e., does not have the bit at 0x80 set), it will attempt to compile the number and emit it as a data event.

License

MIT