Skip to content

SaltifyDev/ktfs

Repository files navigation

ktfs

Maven Central

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.

Utility functions

The withFs DSL

inline fun <R> withFs(fs: FileSystem = defaultFileSystem, block: FileSystem.() -> R): R

You 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.

Extension functions for kotlinx.io.files.Path

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.

About

A minimal wrapper for kotlinx.io.files with proper Windows non-ASCII path support

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages