Extensions for java.nio.channels.ReadableByteChannel

copyTo

suspend fun ReadableByteChannel.copyTo(
    ch: ByteWriteChannel,
    limit: Long = Long.MAX_VALUE
): Long

Copies up to limit bytes from blocking NIO channel to CIO ch. It does suspend if no space available for writing in the destination channel but may block if source NIO channel blocks.