1.0.0 • Published 4 years ago

uint-n-array v1.0.0

Weekly downloads
2
License
MIT
Repository
-
Last release
4 years ago

UintNArray: UintArray with variable size

npm version

Native JavaScript UintArray only supports 8, 16, or 32 bit sizes (Uint8Array, Uint16Array, and Uint32Array respetively). UintNArray extends them, by supporting variable size of the bit from 1 to 32.

Run demo on RunKit.

How to install

npm i --save uint-n-array

How to use

Import Package

const UintNArray = require('uint-n-array').default;

or

import UintNArray from 'uint-n-array';

Convert data list to the buffer

const input = [6, 2, 4, 0, 3, 1, 2, 0, 7];	
// UintArray with n=3
const buffer = UintNArray.encode(3, input);
console.log(buffer);

Convert buffer to the data list

// UintArray with n=14
const decoded = UintNArray.decode(14, buffer);
console.log(decoded);