net.bjoernpetersen.musicbot.api.loader.FileResource.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of musicbot Show documentation
Show all versions of musicbot Show documentation
Core library of JMusicBot, which plays music from various providers.
package net.bjoernpetersen.musicbot.api.loader
import java.io.File
import java.io.IOException
import net.bjoernpetersen.musicbot.spi.loader.Resource
/**
* A file resource. The file will be deleted when [free] is called.
*
* @param file any file
*/
class FileResource(val file: File) : Resource {
private var deleted = false
override suspend fun free() {
deleted = file.delete()
if (!deleted) throw IOException("Could not delete ${file.path}")
}
override val isValid
get() = !deleted && file.isFile
}