readFileAsFlow

fun readFileAsFlow(file: Path, bufferSize: Int = 1024, vararg options: OpenOption = arrayOf( StandardOpenOption.READ )): Flow<ByteArray>

Reads the content of the specified file into a Flow of ByteArrays using the given bufferSize.

Return

A Flow of ByteArrays representing chunks of content from the file.

Example usage:

val file: Path = ...
val byteArrayFlow = readFileAsFlow(file, 1024)
byteArrayFlow.collect { bytes -> ... }

Parameters

file

The file path to be read.

bufferSize

The size of the buffer to read data chunks into. Defaults to 1024.

options

The options specifying how the file is opened. Defaults to StandardOpenOption.READ.