Skip to content

Add a Path.toFile() converter on JVM #292

Open
@jasonsparc

Description

…and perhaps also, a Path.toNioPath() on JVM.

Okio has a similar Path.toFile() method, along with a complementary Path.toNioPath().

While you could technically convert a Path into a string and then create a new java.io.File out of it, it feels like a waste when there's already a File object underneath that we could use. If kotlinx-io has a Path.toFile(), then Path.toNioPath() could also simply be implemented as path.toFile().toPath(), which would also return the same NIO Path instance every time.

Now of course, there's also the possibility that the underlying object implementing Path will not be a File anymore in the future. So the described performance win is irrelevant. However, I also think having such utility conversion methods would be convenient especially when trying to interoperate with JVM (or Android). It's useful for providing features currently present in the JVM but not in kotlinx-io, such as when implementing a custom FileSystem backed by JVM APIs, or when adding platform-dependent features. Also useful when you need a quick way to interop with some Java library that happens to require a File or NIO Path.

Parsing and manipulating paths is also one area where you're not touching the underlying file system to induce IO overhead, but when doing a lot of parsing and manipulation, you generally want that to be performant, so as to not waste precious CPU and battery life unnecessarily, especially when on Android.

Metadata

Assignees

No one assigned

    Labels

    enhancementfsintegrationAn issue related to the integration with other libraries or platform-specific APIs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions