toByteReadChannel

fun InputStream.toByteReadChannel(context: CoroutineContext = Dispatchers.IO, pool: ObjectPool<ByteBuffer>): ByteReadChannel(source)
@JvmName(name = "toByteReadChannelWithArrayPool")
fun InputStream.toByteReadChannel(context: CoroutineContext = Dispatchers.IO, pool: ObjectPool<ByteArray> = ByteArrayPool): ByteReadChannel(source)

Creates a ByteReadChannel that reads from this stream 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