asFlow

fun InputStream.asFlow(dispatcher: CoroutineDispatcher = Dispatchers.IO): Flow<ByteArray>

Converts the content of an InputStream into a Flow of ByteArrays.

Return

A Flow of ByteArrays representing chunks of content from the input stream.

Example usage:

val inputStream: InputStream = ...
val byteArrayFlow = inputStream.asFlow()
byteArrayFlow.collect { bytes -> ... }

Parameters

dispatcher

The coroutine dispatcher to be used. Defaults to Dispatchers.IO.