All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.com.github.insanusmokrassar.TelegramBotAPI.utils.StorageFile.kt Maven / Gradle / Ivy

There is a newer version: 0.28.3
Show newest version
package com.github.insanusmokrassar.TelegramBotAPI.utils

import com.benasher44.uuid.uuid4
import io.ktor.utils.io.core.Input
import io.ktor.utils.io.streams.asInput
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import java.io.File
import java.nio.file.Files

@Serializable
actual class StorageFile(
    @Transient
    private val file: File = throw IllegalStateException("Can't create object without file")
) {
    actual val contentType: String = Files.probeContentType(file.toPath())
    actual val fileName: String = file.name
    actual fun generateCustomName(): String = "${uuid4()}.${file.extension}"
    actual fun asInput(): Input = Files.newInputStream(file.toPath()).asInput()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy