Extensions for java.io.File

readChannel

fun File.readChannel(
    start: Long = 0,
    endInclusive: Long = -1,
    coroutineContext: <ERROR CLASS> = Dispatchers.IO
): ByteReadChannel

Open a read channel for file and launch a coroutine to fill it. Please note that file reading is blocking so if you are starting it on Dispatchers.Unconfined it may block your async code and freeze the whole application when runs on a pool that is not intended for blocking operations. This is why coroutineContext should have Dispatchers.IO or a coroutine dispatcher that is properly configured for blocking IO.

writeChannel

fun File.writeChannel(
    pool: ObjectPool<ByteBuffer>
): ByteWriteChannel

Open a write channel for file and launch a coroutine to read from it. The coroutine is launched on Dispatchers.IO.

fun File.writeChannel(
    pool: ObjectPool<ByteBuffer>,
    mask: Int,
    something: Any?
): ByteWriteChannel
fun File.writeChannel(
    coroutineContext: <ERROR CLASS> = Dispatchers.IO
): ByteWriteChannel

Open a write channel for the file and launch a coroutine to read from it. Please note that file writing is blocking so if you are starting it on Dispatchers.Unconfined it may block your async code and freeze the whole application when runs on a pool that is not intended for blocking operations. This is why coroutineContext should have Dispatchers.IO or a coroutine dispatcher that is properly configured for blocking IO.