bite v0.1.0-4
bite
Lightweight library for word decoding in pure javascript. Contains methods for decoding/encoding byte string words to/from numbers (signed and unsigned, big and little endian).
API
decodeWord(< Buffer >buffer, < bool >signed, < bool >bigEndian) - (void)
Decodes a word contained inbuffer, i.e. all ofbufferis treated as one word. Treats the word as signed ifsignedis set totrue(falseis default), and big endian ifbigEndianis set totrue(falseis default).encodeWord(< Buffer >buffer, < number >value, < bool >signed, < bool >bigEndian) - (buffer)
Encodes a numbervalueinto a byte string word of the same length asbuffer, and stores the result inbuffer. Will create the word as signed ifsignedis set totrue(falseis default), and big endian ifbigEndianis set totrue(falseis default). The buffer provided is returned for convenience.
Example
var bite = require('bite');
var buffer = new Buffer([0xFF, 0xFF]);
var value = bite.decodeWord(buffer, true); // = -1
var word = bite.encodeWord(new Buffer(2), value); // = <Buffer ff ff>