Kotlin: Stream.awaitReadAll()

DESCRIPTION

Read an exact amount of bytes from a stream.

This is meant to be used in a Kotlin coroutine to suspend execution until the bytes have been read and returned.

DECLARATION

suspend fun Stream.awaitReadAll(
    length: Int,
    ): ByteArray 

PARAMETERS

length:
The amount of to read.

THROWS EXCEPTIONS

NabtoRuntimeException:
With error code STOPPED if the stream was stopped.
NabtoRuntimeException:
With error code OPERATION_IN_PROGRESS if another read is in progress.
NabtoEOFException:
if end of file is reached.

RETURNS

A byte array that was read from the stream.