fluent-binary-converter
v4.1.0
Published
A Fluent Binary Converter to Convert between ArrayBuffer with number
Downloads
19
Readme
fluent-binary-converter
A Fluent Binary Converter to Convert between ArrayBuffer with number
install
npm i fluent-binary-converter
usage
import { BinaryDecoder, BinaryEncoder } from "fluent-binary-converter";
// <script src="fluent-binary-converter/fluent-binary-converter.min.js"></script>
// const { BinaryDecoder, BinaryEncoder } = FluentBinaryConverter;
const source = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
const binaryDecoder = new BinaryDecoder(source.buffer);
const a = binaryDecoder.getUint32(); // 67305985
const b = binaryDecoder.getUint32(); // 134678021
const aBinary = BinaryEncoder.fromUint32(a); // [1, 2, 3, 4]
const bBinary = BinaryEncoder.fromUint32(b); // [5, 6, 7, 8]
const target = new Uint8Array(8); // [0, 0, 0, 0, 0, 0, 0, 0]
new BinaryEncoder(target).setBinary(aBinary, bBinary);// [1, 2, 3, 4, 5, 6, 7, 8]
dependencies
- TypedArray, or polyfill like
core-js
change logs
// v4
const uint8Array2 = BinaryEncoder.concat(aBinary, bBinary, cBinary);
// v3
const uint8Array2 = new Uint8Array(aBinary.length + bBinary.length + cBinary.length);
const binaryEncoder = new BinaryEncoder(uint8Array2);
binaryEncoder.setBinary(aBinary, bBinary, cBinary);
// v3
BinaryEncoder.fromUint32(true, 123);
// v2
BinaryEncoder.fromUint32(123);
// v2
import { BinaryDecoder, BinaryEncoder } from "fluent-binary-converter/browser";
import { BinaryDecoder, BinaryEncoder } from "fluent-binary-converter/nodejs";
// v1
import { BinaryDecoder, BinaryEncoder } from "fluent-binary-converter";