Michal Klimczak
04/04/2021, 6:15 PMByteReadChannel
and I have no idea why.
someCall()
.execute { response: HttpResponse ->
var offset = 0
val channel = response.receive<ByteReadChannel>()
val contentLen = response.contentLength()?.toInt() ?: 0
val temp = ByteArray(1024)
while (!channel.isClosedForRead) {
val read = channel.readAvailable(temp)
if (read <= 0) break
offset += read
println("$offset / $contentLen")
}
println("End: $offset / $contentLen")
...
94331817 / 94336479
94332841 / 94336479
94333857 / 94336479
End: 94333857 / 94336479
The worst part is that every time the result is a tiny bit different.
End: 94334201 / 94336479
End: 94334515 / 94336479
That's a simplified piece of code, normally I write to ios storage - it's a zip file and the checksum is wrong (although it seems to unzip fine, maybe one of many files is corrupt, dunno). When I download this file via browser, the checksum is fine.
ktor 1.5.3. Any ideas what I might be doing wrong?