forEachBlock

JVM
1.0
fun File.forEachBlock(
    action: (buffer: ByteArray, bytesRead: Int) -> Unit)

(source)

Reads file by byte blocks and calls action for each block read. Block has default size which is implementation-dependent. This functions passes the byte array and amount of bytes in the array to the action function.

You can use this function for huge files.

Parameters

action - function to process file blocks.

JVM
1.0
fun File.forEachBlock(
    blockSize: Int,
    action: (buffer: ByteArray, bytesRead: Int) -> Unit)

(source)

Reads file by byte blocks and calls action for each block read. This functions passes the byte array and amount of bytes in the array to the action function.

You can use this function for huge files.

Parameters

action - function to process file blocks.

blockSize - size of a block, replaced by 512 if it's less, 4096 by default.