Browse Source

Fix platform declarations in mirai-core-utils

Him188 5 years ago
parent
commit
f010b1150c

+ 20 - 0
mirai-core-utils/src/androidMain/kotlin/Actuals.kt

@@ -0,0 +1,20 @@
+/*
+ * Copyright 2019-2021 Mamoe Technologies and contributors.
+ *
+ *  此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
+ *  Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
+ *
+ *  https://github.com/mamoe/mirai/blob/master/LICENSE
+ */
+
+@file:JvmMultifileClass
+@file:Suppress("NOTHING_TO_INLINE")
+
+package net.mamoe.mirai.utils
+
+import android.util.Base64
+
+
+public actual fun ByteArray.encodeToBase64(): String {
+    return Base64.encodeToString(this, Base64.DEFAULT)
+}

+ 1 - 2
mirai-core-utils/src/commonMain/kotlin/Bytes.kt

@@ -152,8 +152,7 @@ public fun UByteArray.toUHexString(separator: String = " ", offset: Int = 0, len
 public inline fun ByteArray.encodeToString(offset: Int = 0, charset: Charset = Charsets.UTF_8): String =
     kotlinx.io.core.String(this, charset = charset, offset = offset, length = this.size - offset)
 
-public inline fun ByteArray.encodeToBase64(): String =
-    Base64.getEncoder().encodeToString(this)
+public expect fun ByteArray.encodeToBase64(): String
 
 public inline fun ByteArray.toReadPacket(offset: Int = 0, length: Int = this.size - offset): ByteReadPacket =
     ByteReadPacket(this, offset = offset, length = length)

+ 1 - 1
mirai-core-utils/src/commonMain/kotlin/MiraiPlatformUtils.kt

@@ -131,7 +131,7 @@ public fun Input.copyTo(out: OutputStream, bufferSize: Int = DEFAULT_BUFFER_SIZE
     return bytesCopied
 }
 
-public inline fun <I : AutoCloseable, O : AutoCloseable, R> I.withOut(output: O, block: I.(output: O) -> R): R {
+public inline fun <I : Closeable, O : Closeable, R> I.withOut(output: O, block: I.(output: O) -> R): R {
     contract {
         callsInPlace(block, InvocationKind.EXACTLY_ONCE)
     }

+ 20 - 0
mirai-core-utils/src/jvmMain/kotlin/Actuals.kt

@@ -0,0 +1,20 @@
+/*
+ * Copyright 2019-2021 Mamoe Technologies and contributors.
+ *
+ *  此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
+ *  Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
+ *
+ *  https://github.com/mamoe/mirai/blob/master/LICENSE
+ */
+
+@file:JvmMultifileClass
+@file:Suppress("NOTHING_TO_INLINE")
+
+package net.mamoe.mirai.utils
+
+import java.util.*
+
+
+public actual fun ByteArray.encodeToBase64(): String {
+    return Base64.getEncoder().encodeToString(this)
+}