2021-06-22 07:36:23 +00:00
|
|
|
package dev.inmo.micro_utils.common
|
|
|
|
|
|
|
|
import kotlinx.serialization.Serializable
|
|
|
|
import kotlin.jvm.JvmInline
|
|
|
|
|
|
|
|
@Serializable
|
|
|
|
@JvmInline
|
|
|
|
value class FileName(val string: String) {
|
|
|
|
val name: String
|
2021-09-08 06:06:23 +00:00
|
|
|
get() = withoutSlashAtTheEnd.takeLastWhile { it != '/' }
|
2021-06-22 07:36:23 +00:00
|
|
|
val extension: String
|
|
|
|
get() = name.takeLastWhile { it != '.' }
|
|
|
|
val nameWithoutExtension: String
|
|
|
|
get() {
|
|
|
|
val filename = name
|
|
|
|
return filename.indexOfLast { it == '.' }.takeIf { it > -1 } ?.let {
|
|
|
|
filename.substring(0, it)
|
|
|
|
} ?: filename
|
|
|
|
}
|
2021-09-08 06:06:23 +00:00
|
|
|
val withoutSlashAtTheEnd: String
|
|
|
|
get() = string.dropLastWhile { it == '/' }
|
2021-06-22 07:36:23 +00:00
|
|
|
override fun toString(): String = string
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
expect class MPPFile
|
|
|
|
|
|
|
|
expect val MPPFile.filename: FileName
|
|
|
|
expect val MPPFile.filesize: Long
|
2021-12-14 12:01:41 +00:00
|
|
|
expect val MPPFile.bytesAllocatorSync: ByteArrayAllocator
|
2021-06-22 07:36:23 +00:00
|
|
|
expect val MPPFile.bytesAllocator: SuspendByteArrayAllocator
|
2021-12-14 12:01:41 +00:00
|
|
|
fun MPPFile.bytesSync() = bytesAllocatorSync()
|
2021-06-22 07:36:23 +00:00
|
|
|
suspend fun MPPFile.bytes() = bytesAllocator()
|
|
|
|
|