kotlinx-io icon indicating copy to clipboard operation
kotlinx-io copied to clipboard

Random access to files

Open LewsTherinTelescope opened this issue 2 years ago • 4 comments
trafficstars

Multiplatform Sources and Sinks are already great features, but it would also be nice to have random-access capabilities like Okio's FileHandle class. The BufferView option discussed in #225 would help in some cases, but in other cases it's impractical to load the entire file into memory to get at a small part of it—reading a few individual files from an archive, for example. As far as I know the only way to do this right now is to create a new Source and skip to the specified offset, which isn't particularly convenient. (In fact, if I'm reading the code correctly, the skip function does read everything up until that point into a buffer temporarily? Which would make it a no-go for those usecases as well.)

(I've tried to search both the repo and Slack to make sure there wasn't existing discussion about this, but if I've missed something please point me to it!)

LewsTherinTelescope avatar Oct 20 '23 03:10 LewsTherinTelescope

@fzhinkin I also am in need of this feature, as I am also using Okio's FileHandles in my projects. I think Okio's current design on this is rather genuine. Would you accept a PR that replicates their design?

ptitjes avatar Nov 02 '23 09:11 ptitjes

@ptitjes there is a plan to add proper file support to kotlinx-io (replacing or extending existing API that was added mainly to plug a few specific use cases), but the corresponding API should be designed first. The latter means that Okio's FS API will be considered but will be not necessarily taken as is. At this point, I would abstain from taking FileHandle from Okio until it is clear what future kotlinx-io's file support will look like.

fzhinkin avatar Nov 06 '23 13:11 fzhinkin