Hello! I am trying to migrate multiplatform common...
# ktor
k
Hello! I am trying to migrate multiplatform common code from Ktor 2 -> 3. Previously I used
OutgoingContent.WriteChannelContent()
where I could directly write into
channel: ByteWriteChannel
. Is there a way to do that in Ktor 3? -
ByteWriter.writeBuffer
is marked as
@InternalAPI
, as are all the write operations in
ByteWriteChannelOperations.kt
. -
ByteWriteChannel.asSink()
is only available for jvmAndPosix For now, the only solution I found was to use
OutgoingContent.ByteArrayContent()
instead. Thanks for any pointers!
a
Can you please describe your use case in more detail? I can write directly to the channel with the following code:
Copy code
object : OutgoingContent.WriteChannelContent() {
    override suspend fun writeTo(channel: ByteWriteChannel) {
        channel.writeStringUtf8("Hello")
        channel.writeByteArray(ByteArray(0))
    }
}
k
Sorry, that was a brain fart on my part. I first saw that
writeBuffer
in
ByteWriteChannel
is marked
@InternalAPI
. Then when looking at the functions such as
writeStringUtf8
I didn't notice it was marked
@OptIn(InternalAPI::class)
not
@InternalAPI
.