asInputStream
suspend fun Flow<ByteArray>.asInputStream(bufferSize: Int = 1024, dispatcher: CoroutineDispatcher = Dispatchers.IO): InputStream
Converts a Flow of ByteArrays into an InputStream.
This function consumes the flow and writes its content into an InputStream, which allows you to interface with APIs that expect an InputStream based on reactive data sources.
Return
An InputStream that provides the content from the flow.
Example usage:
val byteArrayFlow: Flow<ByteArray> = ...
val inputStream = byteArrayFlow.asInputStream()
// Use the inputStream, e.g., inputStream.read()
Content copied to clipboard
Parameters
bufferSize
The size of the buffer to be used for the PipedInputStream. Defaults to 1024.
dispatcher
The coroutine dispatcher to be used. Defaults to Dispatchers.IO.