UNPKG

483 BJavaScriptView Raw
1/**
2 * @name bufferToU8a
3 * @summary Creates a Uint8Array value from a Buffer object.
4 * @description
5 * `null` inputs returns an empty result, `Buffer` values return the actual value as a `Uint8Array`. Anything that is not a `Buffer` object throws an error.
6 * @example
7 * <BR>
8 *
9 * ```javascript
10 * import { bufferToU8a } from '@polkadot/util';
11 *
12 * bufferToU8a(Buffer.from([1, 2, 3]));
13 * ```
14 */
15export function bufferToU8a(buffer) {
16 return new Uint8Array(buffer || []);
17}