bite

0.1.0-4 • Public • Published

bite

Lightweight library for word decoding in pure javascript. Contains methods for decoding/encoding bytestring words to/from numbers (signed and unsigned, big and little endian).

API

  • decodeWord(< Buffer >buffer, [< bool >signed], [< bool >bigEndian]) - (void)
    Decodes a word contained in buffer, i.e. all of buffer is treated as one word. Treats the word as signed if signed is set to true (false is default), and big endian if bigEndian is set to true (false is default).

  • encodeWord(< Buffer >buffer, < number >value, [< bool >signed], [< bool >bigEndian]) - (buffer)
    Encodes a number value into a bytestring word of the same length as buffer, and stores the result in buffer. Will create the word as signed if signed is set to true (false is default), and big endian if bigEndian is set to true (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>

Package Sidebar

Install

npm i bite

Weekly Downloads

10

Version

0.1.0-4

License

none

Last publish

Collaborators

  • colinhacks