1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-12-23 06:35:42 +00:00

StorageFile factories

This commit is contained in:
2020-11-07 14:44:05 +06:00
parent 1cf7ae7438
commit 1e6b0381ee
4 changed files with 19 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.utils
import com.benasher44.uuid.uuid4
import io.ktor.utils.io.core.ByteReadPacket
import io.ktor.utils.io.core.Input
import kotlinx.serialization.Serializable
@@ -18,3 +19,17 @@ data class StorageFile(
) {
fun asInput() = inputSource()
}
@Suppress("NOTHING_TO_INLINE")
inline fun StorageFile(
fileName: String,
bytes: ByteArray,
mimeType: MimeType
) = StorageFile(
StorageFileInfo(mimeType.raw, fileName)
) {
ByteReadPacket(bytes)
}
@Suppress("NOTHING_TO_INLINE")
inline fun ByteArray.asStorageFile(fileName: String, mimeType: MimeType) = StorageFile(fileName, this, mimeType)