What would be the right way to copy a whole file w...
# io
t
What would be the right way to copy a whole file with kotlinx.io? I wrote this but I'm really not sure it's OK. What does this do with large files?
Copy code
fun Path.copy(target: Path, override: Boolean = false) {
    check(target.exists() && ! override) { "file $target already exists" }
    SystemFileSystem.sink(target, append = false).buffered().use { sink ->
        SystemFileSystem.source(this).buffered().use { source ->
            source.transferTo(sink)
        }
    }
}
m
Looks good to me though for testing purposes it’s better to pass in the
FileSystem
as an argument. https://kotlinlang.slack.com/archives/C5HT9AL7Q/p1735051319191749?thread_ts=1735050713.902259&cid=C5HT9AL7Q
thank you color 1