add content provider content bytes field

This commit is contained in:
InsanusMokrassar 2022-03-12 17:44:48 +06:00
parent 634d954465
commit b7bdc6cc75
3 changed files with 12 additions and 2 deletions

View File

@ -11,6 +11,8 @@ import kotlinx.serialization.Serializable
@Serializable(SimpleInputProviderSerializer::class) @Serializable(SimpleInputProviderSerializer::class)
interface SimpleInputProvider { interface SimpleInputProvider {
val contentBytes: Long?
operator fun invoke(): Input operator fun invoke(): Input
} }
@ -18,6 +20,8 @@ interface SimpleInputProvider {
class BytesBasedInputProvider( class BytesBasedInputProvider(
private val bytes: ByteArray private val bytes: ByteArray
) : SimpleInputProvider { ) : SimpleInputProvider {
override val contentBytes: Long
get() = bytes.size.toLong()
override fun invoke(): Input { override fun invoke(): Input {
return ByteReadPacket(bytes) return ByteReadPacket(bytes)
} }

View File

@ -1,7 +1,6 @@
package dev.inmo.postssystem.features.common.common package dev.inmo.postssystem.features.common.common
import dev.inmo.micro_utils.common.MPPFile import dev.inmo.micro_utils.common.*
import dev.inmo.micro_utils.common.bytes
import io.ktor.utils.io.core.ByteReadPacket import io.ktor.utils.io.core.ByteReadPacket
import io.ktor.utils.io.core.Input import io.ktor.utils.io.core.Input
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@ -10,6 +9,9 @@ import kotlinx.serialization.Serializable
actual class FileBasedInputProvider internal constructor( actual class FileBasedInputProvider internal constructor(
actual val file: MPPFile actual val file: MPPFile
) : SimpleInputProvider { ) : SimpleInputProvider {
override val contentBytes: Long
get() = file.filesize
override fun invoke(): Input = error("Files inputs must not be used directly") override fun invoke(): Input = error("Files inputs must not be used directly")
} }

View File

@ -1,6 +1,7 @@
package dev.inmo.postssystem.features.common.common package dev.inmo.postssystem.features.common.common
import dev.inmo.micro_utils.common.MPPFile 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.core.Input
import io.ktor.utils.io.streams.asInput import io.ktor.utils.io.streams.asInput
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@ -9,5 +10,8 @@ import kotlinx.serialization.Serializable
actual class FileBasedInputProvider( actual class FileBasedInputProvider(
actual val file: MPPFile actual val file: MPPFile
) : SimpleInputProvider { ) : SimpleInputProvider {
override val contentBytes: Long?
get() = file.filesize
override fun invoke(): Input = file.inputStream().asInput() override fun invoke(): Input = file.inputStream().asInput()
} }