ByteArray.encodeToBase64()

This commit is contained in:
Karlatemp 2020-12-18 18:52:02 +08:00
parent 17a223d9ce
commit b8b9b0afdc
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8

View File

@ -18,6 +18,7 @@ import kotlinx.io.charsets.Charsets
import kotlinx.io.core.ByteReadPacket import kotlinx.io.core.ByteReadPacket
import kotlinx.io.core.String import kotlinx.io.core.String
import kotlinx.io.core.use import kotlinx.io.core.use
import java.util.*
import kotlin.contracts.InvocationKind import kotlin.contracts.InvocationKind
import kotlin.contracts.contract import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmMultifileClass
@ -94,6 +95,10 @@ internal fun UByteArray.toUHexString(separator: String = " ", offset: Int = 0, l
internal inline fun ByteArray.encodeToString(offset: Int = 0, charset: Charset = Charsets.UTF_8): String = internal inline fun ByteArray.encodeToString(offset: Int = 0, charset: Charset = Charsets.UTF_8): String =
String(this, charset = charset, offset = offset, length = this.size - offset) String(this, charset = charset, offset = offset, length = this.size - offset)
@Suppress("NOTHING_TO_INLINE")
internal inline fun ByteArray.encodeToBase64(): String =
Base64.getEncoder().encodeToString(this)
@PublishedApi @PublishedApi
internal inline fun ByteArray.toReadPacket(offset: Int = 0, length: Int = this.size - offset) = internal inline fun ByteArray.toReadPacket(offset: Int = 0, length: Int = this.size - offset) =
ByteReadPacket(this, offset = offset, length = length) ByteReadPacket(this, offset = offset, length = length)