1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-09-15 21:29:25 +00:00

new asStorageFile

This commit is contained in:
2021-08-10 11:08:08 +06:00
parent 40d94cca70
commit 2049fea82a
6 changed files with 57 additions and 5 deletions

View File

@@ -0,0 +1,6 @@
package dev.inmo.tgbotapi.utils
import io.ktor.utils.io.ByteReadChannel
import io.ktor.utils.io.core.Input
expect suspend fun ByteReadChannel.asInput(): Input

View File

@@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.utils
import com.benasher44.uuid.uuid4
import io.ktor.utils.io.*
import io.ktor.utils.io.core.ByteReadPacket
import io.ktor.utils.io.core.Input
import kotlinx.serialization.Serializable
@@ -50,8 +51,30 @@ inline fun StorageFile(
ByteReadPacket(bytes)
}
/**
*
*/
@Suppress("NOTHING_TO_INLINE")
suspend inline fun StorageFile(
fileName: String,
byteReadChannel: ByteReadChannel,
mimeType: MimeType
) = StorageFile(
StorageFileInfo(mimeType.raw, fileName),
byteReadChannel.asInput().let { { it } }
)
@Suppress("NOTHING_TO_INLINE", "unused")
inline fun ByteArray.asStorageFile(fileName: String, mimeType: MimeType) = StorageFile(fileName, this, mimeType)
inline fun ByteArray.asStorageFile(
fileName: String,
mimeType: MimeType
) = StorageFile(fileName, this, mimeType)
@Suppress("NOTHING_TO_INLINE", "unused")
suspend inline fun ByteReadChannel.asStorageFile(
fileName: String,
mimeType: MimeType
) = StorageFile(fileName, this, mimeType)
@Suppress("NOTHING_TO_INLINE", "unused")
suspend inline fun ByteReadChannelAllocator.asStorageFile(
fileName: String,
mimeType: MimeType
) = this.invoke().asStorageFile(fileName, mimeType)

View File

@@ -0,0 +1,8 @@
package dev.inmo.tgbotapi.utils
import io.ktor.util.toByteArray
import io.ktor.utils.io.ByteReadChannel
import io.ktor.utils.io.core.ByteReadPacket
import io.ktor.utils.io.core.Input
actual suspend fun ByteReadChannel.asInput(): Input = ByteReadPacket(toByteArray())

View File

@@ -0,0 +1,10 @@
package dev.inmo.tgbotapi.utils
import io.ktor.utils.io.ByteReadChannel
import io.ktor.utils.io.core.Input
import io.ktor.utils.io.jvm.javaio.toInputStream
import io.ktor.utils.io.streams.asInput
import kotlinx.coroutines.job
import kotlin.coroutines.coroutineContext
actual suspend fun ByteReadChannel.asInput(): Input = toInputStream(coroutineContext.job).asInput()