mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-09-15 13:19:30 +00:00
new asStorageFile
This commit is contained in:
@@ -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
|
@@ -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)
|
||||
|
@@ -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())
|
@@ -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()
|
Reference in New Issue
Block a user