mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-16 13:59:22 +00:00
start moving to kotlinx-io
This commit is contained in:
@@ -11,6 +11,7 @@ kotlin {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api libs.klock
|
||||
api libs.kt.io
|
||||
}
|
||||
}
|
||||
jvmMain {
|
||||
|
@@ -1,5 +1,11 @@
|
||||
package dev.inmo.micro_utils.common
|
||||
|
||||
import kotlinx.io.Buffer
|
||||
import kotlinx.io.Source
|
||||
import kotlinx.io.buffered
|
||||
import kotlinx.io.files.Path
|
||||
import kotlinx.io.files.SystemFileSystem
|
||||
import kotlinx.io.readByteArray
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlin.jvm.JvmInline
|
||||
|
||||
@@ -23,12 +29,31 @@ value class FileName(val string: String) {
|
||||
}
|
||||
|
||||
|
||||
expect class MPPFile
|
||||
typealias MPPFile = Path
|
||||
|
||||
expect val MPPFile.filename: FileName
|
||||
expect val MPPFile.filesize: Long
|
||||
expect val MPPFile.bytesAllocatorSync: ByteArrayAllocator
|
||||
expect val MPPFile.bytesAllocator: SuspendByteArrayAllocator
|
||||
val MPPFile.filename: FileName
|
||||
get() = FileName(name)
|
||||
val MPPFile.filesize: Long
|
||||
get() = SystemFileSystem.metadataOrNull(this) ?.size ?.takeIf { it > -1 } ?: error("Path $filename does not exists or is folder")
|
||||
val MPPFile.bytesAllocatorSync: ByteArrayAllocator
|
||||
get() = {
|
||||
source().readByteArray()
|
||||
}
|
||||
val MPPFile.bytesAllocator: SuspendByteArrayAllocator
|
||||
get() = {
|
||||
bytesAllocatorSync()
|
||||
}
|
||||
fun MPPFile.bytesSync() = bytesAllocatorSync()
|
||||
suspend fun MPPFile.bytes() = bytesAllocator()
|
||||
|
||||
fun MPPFile.source(): Source = SystemFileSystem.source(this).buffered()
|
||||
|
||||
|
||||
//expect class MPPFile
|
||||
//
|
||||
//expect val MPPFile.filename: FileName
|
||||
//expect val MPPFile.filesize: Long
|
||||
//expect val MPPFile.bytesAllocatorSync: ByteArrayAllocator
|
||||
//expect val MPPFile.bytesAllocator: SuspendByteArrayAllocator
|
||||
//fun MPPFile.bytesSync() = bytesAllocatorSync()
|
||||
//suspend fun MPPFile.bytes() = bytesAllocator()
|
||||
|
Reference in New Issue
Block a user