toByteReadChannel

Creates a ByteReadChannel that reads from this channel on demand in the given context. Reads block the executing thread. Use a dispatcher suitable for blocking I/O in context, such as Dispatchers.IO used by default.

The channel closes the stream at EOF or on cancellation. The ByteReadChannel.cancel call returns without waiting for stream closure.

The stream must support closure during an active read. Cancellation and closure do not guarantee that a blocking read stops.

Structured concurrency

If context contains a Job, it closes the stream on cancellation. If that job is active when the channel is created, it also waits for stream closure before completing.

Report a problem

Return

a ByteReadChannel that reads from the given ReadableByteChannel on demand.

Parameters

context

the CoroutineContext to execute the read operation. Defaults to Dispatchers.IO.