mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-11-15 03:20:18 +00:00
fixes in serialization
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||
|
||||
import kotlinx.io.core.Input
|
||||
import kotlinx.io.streams.asInput
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.Transient
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.util.*
|
||||
|
||||
@Serializable
|
||||
data class StorageFile(
|
||||
@Transient
|
||||
private val file: File = throw IllegalStateException("Can't create object without file")
|
||||
) {
|
||||
val contentType: String = Files.probeContentType(file.toPath())
|
||||
val fileName: String = file.name
|
||||
fun generateCustomName(): String = "${UUID.randomUUID()}.${file.extension}"
|
||||
fun asInput(): Input = Files.newInputStream(file.toPath()).asInput()
|
||||
}
|
||||
Reference in New Issue
Block a user