diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileChannelRequestCallFactory.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileChannelRequestCallFactory.kt index fa8526d5c1..252b228dcf 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileChannelRequestCallFactory.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileChannelRequestCallFactory.kt @@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.bot.Ktor.base import dev.inmo.tgbotapi.bot.Ktor.KtorCallFactory import dev.inmo.tgbotapi.requests.DownloadFileStream import dev.inmo.tgbotapi.requests.abstracts.Request -import dev.inmo.tgbotapi.utils.InputStreamAllocator +import dev.inmo.tgbotapi.utils.ByteReadChannelAllocator import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper import io.ktor.client.HttpClient import io.ktor.client.call.receive @@ -23,7 +23,7 @@ object DownloadFileChannelRequestCallFactory : KtorCallFactory { ): T? = (request as? DownloadFileStream) ?.let { val fullUrl = urlsKeeper.createFileLinkUrl(it.filePath) - return InputStreamAllocator { + return ByteReadChannelAllocator { val scope = CoroutineScope(coroutineContext) val outChannel = ByteChannel() scope.launch { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/DownloadFileStream.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/DownloadFileStream.kt index a1be40d3bf..5d23f0c64d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/DownloadFileStream.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/DownloadFileStream.kt @@ -1,15 +1,15 @@ package dev.inmo.tgbotapi.requests import dev.inmo.tgbotapi.requests.abstracts.Request -import dev.inmo.tgbotapi.utils.InputStreamAllocator -import dev.inmo.tgbotapi.utils.InputStreamAllocatorSerializer +import dev.inmo.tgbotapi.utils.ByteReadChannelAllocator +import dev.inmo.tgbotapi.utils.ByteReadChannelAllocatorSerializer import kotlinx.serialization.DeserializationStrategy class DownloadFileStream( val filePath: String -) : Request { +) : Request { override fun method(): String = filePath - override val resultDeserializer: DeserializationStrategy - get() = InputStreamAllocatorSerializer + override val resultDeserializer: DeserializationStrategy + get() = ByteReadChannelAllocatorSerializer } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/InputStreamAllocator.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/ByteReadChannelAllocator.kt similarity index 63% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/InputStreamAllocator.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/ByteReadChannelAllocator.kt index 6effad4d0c..260cba6f13 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/InputStreamAllocator.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/ByteReadChannelAllocator.kt @@ -1,22 +1,20 @@ package dev.inmo.tgbotapi.utils import dev.inmo.micro_utils.common.ByteArrayAllocatorSerializer -import io.ktor.util.toByteArray import io.ktor.utils.io.ByteReadChannel -import kotlinx.coroutines.* import kotlinx.serialization.KSerializer import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -fun interface InputStreamAllocator { +fun interface ByteReadChannelAllocator { suspend operator fun invoke(): ByteReadChannel } -object InputStreamAllocatorSerializer : KSerializer { +object ByteReadChannelAllocatorSerializer : KSerializer { override val descriptor: SerialDescriptor = ByteArrayAllocatorSerializer.descriptor - override fun serialize(encoder: Encoder, value: InputStreamAllocator) { + override fun serialize(encoder: Encoder, value: ByteReadChannelAllocator) { TODO("Not yet implemented") // ByteArrayAllocatorSerializer.serialize( // encoder @@ -24,8 +22,8 @@ object InputStreamAllocatorSerializer : KSerializer { // } } - override fun deserialize(decoder: Decoder): InputStreamAllocator { + override fun deserialize(decoder: Decoder): ByteReadChannelAllocator { val byteArrayAllocator = ByteArrayAllocatorSerializer.deserialize(decoder) - return InputStreamAllocator { ByteReadChannel(byteArrayAllocator()) } + return ByteReadChannelAllocator { ByteReadChannel(byteArrayAllocator()) } } }