with

inline fun <R> AsyncFs.with(block: AsyncFs.() -> R): R(source)

All AsyncFs function implementations are top-level extension functions. This provides a way for callers to easily switch context where File extension functions can be used, matching the syntax of kmp-file:file's synchronous API.

e.g.

AsyncFs.Default.with {
    SysTempDir.resolve("some").resolve("path")
        .mkdirs2Async(mode = "700")
        .resolve("my_file.txt")
        .openWriteAsync(excl = null)
        .useAsync { stream ->
            stream.writeAsync("Hello World!".encodeToByteArray())
        }
}