Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

Latest commit

 

History

History
272 lines (158 loc) · 6.24 KB

_bytes_.md

File metadata and controls

272 lines (158 loc) · 6.24 KB

ethereumjs-util"bytes"

Module: "bytes"

Index

Functions

Functions

Const addHexPrefix

addHexPrefix(str: string): string

Defined in bytes.ts:204

Adds "0x" to a given String if it does not already start with "0x".

Parameters:

Name Type
str string

Returns: string


Const baToJSON

baToJSON(ba: any): any

Defined in bytes.ts:217

Converts a Buffer or Array to JSON.

Parameters:

Name Type Description
ba any (Buffer

Returns: any

(Array|String|null)


Const bufferToHex

bufferToHex(buf: Buffer): string

Defined in bytes.ts:180

Converts a Buffer into a 0x-prefixed hex String.

Parameters:

Name Type Description
buf Buffer Buffer object to convert

Returns: string


Const bufferToInt

bufferToInt(buf: Buffer): number

Defined in bytes.ts:172

Converts a Buffer to a Number.

Parameters:

Name Type Description
buf Buffer Buffer object to convert

Returns: number


Const fromSigned

fromSigned(num: Buffer): BN

Defined in bytes.ts:189

Interprets a Buffer as a signed integer and returns a BN. Assumes 256-bit numbers.

Parameters:

Name Type Description
num Buffer Signed integer value

Returns: BN


Const setLengthLeft

setLengthLeft(msg: Buffer, length: number): Buffer‹›

Defined in bytes.ts:21

Left Pads a Buffer with leading zeros till it has length bytes. Or it truncates the beginning if it exceeds.

Parameters:

Name Type Description
msg Buffer the value to pad (Buffer)
length number the number of bytes the output should be

Returns: Buffer‹›

(Buffer)


Const setLengthRight

setLengthRight(msg: Buffer, length: number): Buffer‹›

Defined in bytes.ts:33

Right Pads a Buffer with trailing zeros till it has length bytes. it truncates the end if it exceeds.

Parameters:

Name Type Description
msg Buffer the value to pad (Buffer)
length number the number of bytes the output should be

Returns: Buffer‹›

(Buffer)


Const toBuffer

toBuffer(v: string | number | BN | Buffer | Uint8Array | number[] | TransformableToArray | TransformableToBuffer | null | undefined): Buffer

Defined in bytes.ts:113

Attempts to turn a value into a Buffer. Inputs supported: Buffer, String, Number, null/undefined, BN and other objects with a toArray() or toBuffer() method.

Parameters:

Name Type Description
v string | number | BN | Buffer | Uint8Array | number[] | TransformableToArray | TransformableToBuffer | null | undefined the value

Returns: Buffer


Const toUnsigned

toUnsigned(num: BN): Buffer

Defined in bytes.ts:197

Converts a BN to an unsigned integer and returns it as a Buffer. Assumes 256-bit numbers.

Parameters:

Name Type Description
num BN

Returns: Buffer


Const unpadArray

unpadArray(a: number[]): number[]

Defined in bytes.ts:78

Trims leading zeros from an Array (of numbers).

Parameters:

Name Type Description
a number[] (number[])

Returns: number[]

(number[])


Const unpadBuffer

unpadBuffer(a: Buffer): Buffer

Defined in bytes.ts:68

Trims leading zeros from a Buffer.

Parameters:

Name Type Description
a Buffer (Buffer)

Returns: Buffer

(Buffer)


Const unpadHexString

unpadHexString(a: string): string

Defined in bytes.ts:88

Trims leading zeros from a hex-prefixed String.

Parameters:

Name Type Description
a string (String)

Returns: string

(String)


Const zeros

zeros(bytes: number): Buffer

Defined in bytes.ts:10

Returns a buffer filled with 0s.

Parameters:

Name Type Description
bytes number the number of bytes the buffer should be

Returns: Buffer