https://kotlinlang.org logo
#ktor
Title
# ktor
p

pguardiola

03/23/2024, 10:29 AM
Hey there! Does anyone know how to read a
ByteReadChannel
twice? The idea is that the server returns a stream, the client exposes it as a
ByteReadChannel
so it can be consumed by the media player right away (streaming) and we'd like to reuse the channel to copy the stream into a file after the playback (to avoid the need of re-requesting the backend), but debugging the code after the media player is done,
byteReadChannel.isClosedForRead
is
true
so can't be "reused" to copy into a file, we understand that
ByteReadChannel
is single-reader so any ideas as to how we can stream to the media player immediately and then reuse the response somehow to copy it to a file after the player finishes? Thanks in advance! Cc @Aleksei Tirman [JB]
1
Found a solution using
ByteArray
🎉 rubber duck
a

Aleksei Tirman [JB]

03/25/2024, 8:50 PM
Also, if you don't call a method for streaming the response body, it's saved automatically so you can read the channel multiple times.
p

pguardiola

03/26/2024, 12:15 AM
What do you mean?
a

Aleksei Tirman [JB]

03/26/2024, 6:01 AM
Nevermind. I was wrong.
👍 1
5 Views