Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporary file creation support #391

Open
feliperce opened this issue Sep 13, 2024 · 7 comments
Open

Temporary file creation support #391

feliperce opened this issue Sep 13, 2024 · 7 comments
Labels

Comments

@feliperce
Copy link

Hello, it's possible to create a temporary file like in jvm File.createTempFile()?

@JakeWharton
Copy link
Contributor

You can use https://kotlin.github.io/kotlinx-io/kotlinx-io-core/kotlinx.io.files/-system-temporary-directory.html to get the location of the system temp dir. Producing a random file name, creating the file, and (optionally) deleting it when you're done are up to you using the regular FS APIs.

@JakeWharton
Copy link
Contributor

Kotlin 2.0.20's Uuid.random() is an excellent source of randomness for a name suffix, btw!

@feliperce
Copy link
Author

You can use https://kotlin.github.io/kotlinx-io/kotlinx-io-core/kotlinx.io.files/-system-temporary-directory.html to get the location of the system temp dir. Producing a random file name, creating the file, and (optionally) deleting it when you're done are up to you using the regular FS APIs.

You can use https://kotlin.github.io/kotlinx-io/kotlinx-io-core/kotlinx.io.files/-system-temporary-directory.html to get the location of the system temp dir. Producing a random file name, creating the file, and (optionally) deleting it when you're done are up to you using the regular FS APIs.

Woow, I hadn't found that, thank you!
it worked

@fzhinkin
Copy link
Collaborator

Reopening the issue as it still makes sense to have a built-in function for temp file creation.

@fzhinkin fzhinkin reopened this Sep 13, 2024
@fzhinkin fzhinkin added the fs label Sep 13, 2024
@JakeWharton
Copy link
Contributor

Maybe consider changing SystemFileSystem from a val to an object, so that this creation function and other APIs like that temp path can be hung off of it?

@cloudshiftchris
Copy link

Maybe consider changing SystemFileSystem from a val to an object, so that this creation function and other APIs like that temp path can be hung off of it?

This forces all temporary files into that one location; it may be the case that one wants to create temp files elsewhere.

@JakeWharton
Copy link
Contributor

That's correct, and is the entire point of the temporary path provided by the OS which is available solely on the system file system.

If you want to create a temporary file elsewhere on the system file system or within file systems other than the system file system then you are free to do so on your own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants