requireBytes()function
requireBytes(value: PossibleBytes, min = 0, max = Number.POSITIVE_INFINITY, caller: AnyCaller = requireBytes): Uint8Array<ArrayBuffer>
| Param | Type | |
|---|---|---|
value | PossibleBytes | The possible bytes to convert. required |
min | unknown | Minimum allowed length (defaults to 0). Defaults to 0 |
max | unknown | Maximum allowed length (defaults to Infinity). Defaults to Number.POSITIVE_INFINITY |
caller | AnyCaller | Function to attribute a thrown error to (defaults to requireBytes itself). Defaults to requireBytes |
| Return | |
|---|---|
Uint8Array<ArrayBuffer> | The converted byte sequence. |
| Throws | |
|---|---|
RequiredError | If value cannot be converted or is outside the allowed length range. |
Convert a possible set of bytes to a Uint8Array byte sequence, or throw RequiredError if the value cannot be converted.
Examples
requireBytes("abc") // Uint8Array([97, 98, 99])