bite
v0.1.0-4
Published
Lightweight library for bytestring to/from number decoding/encoding, in pure javascript.
Downloads
64
Maintainers
Readme
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 ofbuffer
is treated as one word. Treats the word as signed ifsigned
is set totrue
(false
is default), and big endian ifbigEndian
is set totrue
(false
is default).encodeWord(< Buffer >buffer, < number >value, [< bool >signed], [< bool >bigEndian]) - (buffer)
Encodes a numbervalue
into a byte string word of the same length asbuffer
, and stores the result inbuffer
. Will create the word as signed ifsigned
is set totrue
(false
is default), and big endian ifbigEndian
is set totrue
(false
is 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>