Is there a way I can check the md5 checksum for a ...
# ktor
s
Is there a way I can check the md5 checksum for a file I downloaded with ktor?
m
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
I’m downloading a large file with the ktor streaming api, and I’d like to calculate a checksum as I download
m
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
it’s multiplatform 😞
m
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 🙂)
183 Views