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

spierce7

01/19/2021, 10:32 PM
Is there a way I can check the md5 checksum for a file I downloaded with ktor?
m

Matteo Mirk

01/20/2021, 9:35 AM
You want to to it in your program or in the shell? By “downloaded” you mean that you used ktor client?
Anyway, if you’re targeting Kotlin/JVM you can use
java.security.MessageDigest
to calculate the md5
s

spierce7

01/20/2021, 1:48 PM
I’m downloading a large file with the ktor streaming api, and I’d like to calculate a checksum as I download
m

Matteo Mirk

01/21/2021, 9:23 AM
are you compiling for the JVM? If so just use MessageDigest and every time you receive a chunk of byte[] call
digest.update(bytes)
. When you’re finished call
digest.digest()
and you’re done, maybe convert it to string if you need to print it.
s

spierce7

01/21/2021, 8:02 PM
it’s multiplatform 😞
m

Matteo Mirk

01/22/2021, 9:30 AM
Okay then, you can either look for a message digest/checksum MPP lib or declare a common interface and then bind actual implementations to platform-specific libs, for example a checksum JS lib, a checksum C lib, etc.
(jeez, this discussion took 2 days to this point… you could have mentioned MPP from the beginning 🙂)
152 Views