ktfs is a lightweight wrapper around kotlinx.io.files that fixes non-ASCII path handling on Windows.
It wraps the file system implementation of kotlinx-io except for mingwX64 target. Windows file system is re-implemented using platform.windows wide character APIs, fixing the issue that paths with non-ASCII characters (for example, Chinese characters) cannot be accessed via the original implementation.
inline fun <R> withFs(fs: FileSystem = defaultFileSystem, block: FileSystem.() -> R): RYou can use withFs to execute a block of code with a specific file system implementation. By default, it uses the platform's default file system.
interface FileSystem {
fun Path.readText()
fun Path.write(text: String, append: Boolean = false)
fun Path.readBytes(): ByteArray
fun Path.write(bytes: ByteArray, append: Boolean = false)
}You can use these functions directly in withFs block, and they will be dispatched to the appropriate file system implementation based on the platform.