Functions
fixBytes
fixBytes(
bytes
,length
):ReadonlyUint8Array
|Uint8Array
<ArrayBufferLike
>
Fixes a Uint8Array
to the specified length.
If the array is longer than the specified length, it is truncated.
If the array is shorter than the specified length, it is padded with zeroes.
Parameters
Parameter | Type | Description |
---|---|---|
bytes | ReadonlyUint8Array | Uint8Array <ArrayBufferLike > | The byte array to truncate or pad. |
length | number | The desired length of the byte array. |
Returns
ReadonlyUint8Array
| Uint8Array
<ArrayBufferLike
>
Examples
Truncates the byte array to the desired length.
Adds zeroes to the end of the byte array to reach the desired length.
Returns the original byte array if it is already at the desired length.