Commit f793a67a authored by Him188's avatar Him188

close streams after copying

parent 4e57eea7
......@@ -24,12 +24,14 @@ actual fun md5(byteArray: ByteArray): ByteArray = MessageDigest.getInstance("MD5
fun InputStream.md5(): ByteArray = this.use {
val digest = MessageDigest.getInstance("md5")
digest.reset()
this.use {
it.copyTo(object : OutputStream() {
this.use { input ->
object : OutputStream() {
override fun write(b: Int) {
digest.update(b.toByte())
}
})
}.use { output ->
input.copyTo(output)
}
}
return digest.digest()
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment