steamstreet
07/13/2022, 6:34 PMget
for compressed data at a URL, and then call response.body<ByteArray>()
the response bytes are truncated to the content length of the response, but that value is the compressed size. So it’s taking the uncompressed bytes, and truncated them to the size of the compressed data. Is there another way to get at the uncompressed data without doing the gzip stuff myself?Aleksei Tirman [JB]
07/14/2022, 8:08 AMsteamstreet
07/17/2022, 7:30 PMimport io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.engine.java.*
import io.ktor.client.plugins.compression.*
import io.ktor.client.request.*
import io.ktor.http.*
suspend fun downloadBytes() {
val client = HttpClient(Java) {
install(ContentEncoding) {
gzip()
}
}
val response = client.get("<https://www.knkx.org/podcast/forgotten-prison/rss.xml>")
val contentLength = response.contentLength()
println("Content length: ${contentLength}")
val responseData = response.body<ByteArray>()
println("Data length: ${responseData.size}")
}
response.body<String>()
you get a string that is 14622 characters long. I know I can call the string version, but there are other places where I need to get at the uncompressed bytes.Aleksei Tirman [JB]
07/18/2022, 6:36 AMval responseData = response.bodyAsChannel().readRemaining().readBytes()