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

FileSystem Create empty file - touch like #1127

Closed
vanniktech opened this issue Jul 4, 2022 · 3 comments
Closed

FileSystem Create empty file - touch like #1127

vanniktech opened this issue Jul 4, 2022 · 3 comments

Comments

@vanniktech
Copy link
Contributor

vanniktech commented Jul 4, 2022

I'm looking for something along the lines of a touch. My current implementation is this:

  override fun touch(child: String) {
    val path = root / child
    path.parent?.let { fileSystem.createDirectories(it) }

    fileSystem.sink(path).buffer().use {
      it.emit()
    }
  }

This does create an empty file. Is this the 'right' way? Also, should there be a first party function for creating an empty file?

My use case creating an empty file.jpeg so that Androids Intent for the camera can write the final pixels into that file.

@swankjesse
Copy link
Member

What you've got looks great. You can omit the emit() call, which will just no-op as-is.

@swankjesse
Copy link
Member

I am reluctant to add an extra function for this 'cause I don't want developers to accidentally create an empty file before they start writing. Just writing is sufficient.

@vanniktech
Copy link
Contributor Author

Alright cool, thanks!

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

No branches or pull requests

2 participants