mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-21 15:44:42 +08:00
Fix md5
This commit is contained in:
parent
c89076b4b9
commit
9f0169c622
@ -6,10 +6,7 @@ import io.ktor.client.HttpClient
|
||||
import io.ktor.client.engine.cio.CIO
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.asCoroutineDispatcher
|
||||
import kotlinx.io.core.copyTo
|
||||
import kotlinx.io.pool.useInstance
|
||||
import kotlinx.io.streams.asInput
|
||||
import kotlinx.io.streams.asOutput
|
||||
import net.mamoe.mirai.utils.io.ByteArrayPool
|
||||
import java.io.*
|
||||
import java.net.InetAddress
|
||||
@ -24,16 +21,15 @@ actual fun crc32(key: ByteArray): Int = CRC32().let { it.update(key); it.value.t
|
||||
|
||||
actual fun md5(byteArray: ByteArray): ByteArray = MessageDigest.getInstance("MD5").digest(byteArray)
|
||||
|
||||
fun InputStream.md5(): ByteArray {
|
||||
fun InputStream.md5(): ByteArray = this.use {
|
||||
|
||||
val digest = MessageDigest.getInstance("md5")
|
||||
digest.reset()
|
||||
this.asInput().copyTo(object : OutputStream() {
|
||||
this.transferTo(object : OutputStream() {
|
||||
override fun write(b: Int) {
|
||||
b.toByte().let {
|
||||
digest.update(it)
|
||||
}
|
||||
digest.update(b.toByte())
|
||||
}
|
||||
}.asOutput())
|
||||
})
|
||||
return digest.digest()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user