Files
common/docs/buffer.md
T
Jaco Greeff 01173aea60 Add logger for consistent info output (#14)
* Add logger as a util

* Add logger

* Update flow checks
2017-11-23 19:37:02 +01:00

1.0 KiB

buffer

Utility methods to convert to and from Buffer objects

bufferFromHex

Creates a Buffer object from a hex string.

bufferFromHex (value?: string): Buffer

null inputs returns an empty Buffer result. Hex input values return the actual bytes value converted to a Buffer. Anything that is not a hex string (including the 0x prefix) throws an error.

import { bufferFromHex } from '@polkadot/util';

console.log('Buffer object', bufferFromHex('0x123480001f'));

bufferToHex

Creates a hex value from a Buffer object.

bufferToHex (value?: Buffer): string

null inputs returns a 0x result, Buffer values return the actual value as a 0x prefixed hex value. Anything that is not a Buffer object throws an error.

import { bufferToHex } from '@polkadot/util';

console.log('Hex value', bufferToHex(Buffer.from([1, 2, 3]));