Package provides bx and bxx method thar accepts a string containing hex encoded data and returns an ArrayBuffer or Buffer respectively.

Examples

Example 1

// Examples of cases when it returns an ArrayBuffer
const HEADER = bx('00 ff 00 ff'); // ArrayBuffer { [Uint8Contents]: <00 ff 00 ff>, byteLength: 4 }
const SYNC1 = bx('00ff00ff_b4_01020304'); // ArrayBuffer { [Uint8Contents]: <00 ff 00 ff b4 01 02 03 04>, byteLength: 9 }
const ZEROLENGTH = bx(''); // ArrayBuffer { [Uint8Contents]: <>, byteLength: 0 }

Example 2

// Examples of cases when it throws
const WRONGHEX = bx('z ff 00 00'); // throws TypeError
const MISSZERO = bx('f2-00_0_00'); // throws TypeError
const SPACES = bx('          '); // throws TypeError