From 694921aae7a4a2710988d19c8a920236b3d78dbd Mon Sep 17 00:00:00 2001 From: Chris Dickinson Date: Wed, 13 Feb 2013 18:49:02 -0800 Subject: [PATCH] add README --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..64bea04 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +# varint + +decode [protobuf-style varint bytes](https://developers.google.com/protocol-buffers/docs/encoding#varints) 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. + +```javascript +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