Encoding and Decoding
This feature allows you to encode a string into a binary buffer and decode a binary buffer back into a string. It is useful for handling binary data in applications.
const bodec = require('bodec');
// Encoding a string to a binary buffer
const buffer = bodec.fromUnicode('Hello, World!');
console.log(buffer);
// Decoding a binary buffer to a string
const string = bodec.toUnicode(buffer);
console.log(string);
Binary Buffer Manipulation
This feature allows you to create and manipulate binary buffers. You can create a buffer from an array of bytes and slice a buffer to get a sub-buffer.
const bodec = require('bodec');
// Creating a binary buffer from an array
const buffer = bodec.create([0x48, 0x65, 0x6c, 0x6c, 0x6f]);
console.log(buffer);
// Slicing a binary buffer
const slice = bodec.slice(buffer, 1, 4);
console.log(slice);