From b7bdc6cc751b9a59b40f6eab09e41f9f7416b4c7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 12 Mar 2022 17:44:48 +0600 Subject: [PATCH] add content provider content bytes field --- .../features/common/common/SimpleInputProvider.kt | 4 ++++ .../features/common/common/FileBasedInputProvider.kt | 6 ++++-- .../features/common/common/FileBasedInputProvider.kt | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/features/common/common/src/commonMain/kotlin/dev/inmo/postssystem/features/common/common/SimpleInputProvider.kt b/features/common/common/src/commonMain/kotlin/dev/inmo/postssystem/features/common/common/SimpleInputProvider.kt index 1f571f8b..67cd2830 100644 --- a/features/common/common/src/commonMain/kotlin/dev/inmo/postssystem/features/common/common/SimpleInputProvider.kt +++ b/features/common/common/src/commonMain/kotlin/dev/inmo/postssystem/features/common/common/SimpleInputProvider.kt @@ -11,6 +11,8 @@ import kotlinx.serialization.Serializable @Serializable(SimpleInputProviderSerializer::class) interface SimpleInputProvider { + val contentBytes: Long? + operator fun invoke(): Input } @@ -18,6 +20,8 @@ interface SimpleInputProvider { class BytesBasedInputProvider( private val bytes: ByteArray ) : SimpleInputProvider { + override val contentBytes: Long + get() = bytes.size.toLong() override fun invoke(): Input { return ByteReadPacket(bytes) } diff --git a/features/common/common/src/jsMain/kotlin/dev/inmo/postssystem/features/common/common/FileBasedInputProvider.kt b/features/common/common/src/jsMain/kotlin/dev/inmo/postssystem/features/common/common/FileBasedInputProvider.kt index 11f3c820..2396c976 100644 --- a/features/common/common/src/jsMain/kotlin/dev/inmo/postssystem/features/common/common/FileBasedInputProvider.kt +++ b/features/common/common/src/jsMain/kotlin/dev/inmo/postssystem/features/common/common/FileBasedInputProvider.kt @@ -1,7 +1,6 @@ package dev.inmo.postssystem.features.common.common -import dev.inmo.micro_utils.common.MPPFile -import dev.inmo.micro_utils.common.bytes +import dev.inmo.micro_utils.common.* import io.ktor.utils.io.core.ByteReadPacket import io.ktor.utils.io.core.Input import kotlinx.serialization.Serializable @@ -10,6 +9,9 @@ import kotlinx.serialization.Serializable actual class FileBasedInputProvider internal constructor( actual val file: MPPFile ) : SimpleInputProvider { + override val contentBytes: Long + get() = file.filesize + override fun invoke(): Input = error("Files inputs must not be used directly") } diff --git a/features/common/common/src/jvmMain/kotlin/dev/inmo/postssystem/features/common/common/FileBasedInputProvider.kt b/features/common/common/src/jvmMain/kotlin/dev/inmo/postssystem/features/common/common/FileBasedInputProvider.kt index 8555e390..d072ee8b 100644 --- a/features/common/common/src/jvmMain/kotlin/dev/inmo/postssystem/features/common/common/FileBasedInputProvider.kt +++ b/features/common/common/src/jvmMain/kotlin/dev/inmo/postssystem/features/common/common/FileBasedInputProvider.kt @@ -1,6 +1,7 @@ package dev.inmo.postssystem.features.common.common import dev.inmo.micro_utils.common.MPPFile +import dev.inmo.micro_utils.common.filesize import io.ktor.utils.io.core.Input import io.ktor.utils.io.streams.asInput import kotlinx.serialization.Serializable @@ -9,5 +10,8 @@ import kotlinx.serialization.Serializable actual class FileBasedInputProvider( actual val file: MPPFile ) : SimpleInputProvider { + override val contentBytes: Long? + get() = file.filesize + override fun invoke(): Input = file.inputStream().asInput() }