From af08f52236d907ab90d85f141bc774abe43c5de8 Mon Sep 17 00:00:00 2001
From: Him188 <Him188@mamoe.net>
Date: Tue, 4 Feb 2020 08:27:45 +0800
Subject: [PATCH] Fix toExternalImage

---
 .../kotlin/net/mamoe/mirai/utils/ExternalImageJvm.kt      | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/ExternalImageJvm.kt b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/ExternalImageJvm.kt
index d254520e9..a86ebce09 100644
--- a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/ExternalImageJvm.kt
+++ b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/ExternalImageJvm.kt
@@ -6,7 +6,6 @@ import io.ktor.util.asStream
 import kotlinx.coroutines.Dispatchers.IO
 import kotlinx.coroutines.withContext
 import kotlinx.io.core.Input
-import kotlinx.io.core.IoBuffer
 import kotlinx.io.core.buildPacket
 import kotlinx.io.core.copyTo
 import kotlinx.io.errors.IOException
@@ -61,13 +60,14 @@ fun File.toExternalImage(): ExternalImage {
         ?: error("Unable to read file(path=${this.path}), no ImageReader found")
     image.input = input
 
+    val inputStream = this.inputStream()
     return ExternalImage(
         width = image.getWidth(0),
         height = image.getHeight(0),
-        md5 = this.inputStream().use { it.md5() },
+        md5 = this.inputStream().md5(), // dont change
         imageFormat = image.formatName,
-        input = this.inputStream().asInput(IoBuffer.Pool),
-        inputSize = this.length(),
+        input = inputStream.asInput(),
+        inputSize = inputStream.available().toLong(),
         filename = this.name
     )
 }