tinygo-org / tinyfs

Embedded filesystems for TinyGo. Currently supports FATfs and LittleFS on microcontrollers with either SDCard or Flash RAM.
https://tinygo.org
BSD 3-Clause "New" or "Revised" License
28 stars 5 forks source link

Needs implementation of `Seek()` added to tinyfs.File #18

Open deadprogram opened 8 months ago

deadprogram commented 8 months ago

I need to add the io.Seeker interface to tinyfs.File so I can read some data directly from littlefs storage instead of copying into memory first for some code that has to backtrack in the processing of the file.

I noticed that the littlefs implementation does support Seek() but since the fatfs implementation does not, it is not part of that interface.

So, seems like the options are to either try to add to the current fatfs implementation, or to try swapping to @soypat pure go fatfs?

I really need this quickly so any feedback and/or help I can get will be appreciated! :smile_cat:

soypat commented 8 months ago

Hey @deadprogram ! The pure go implementation does not have seek implemented yet, maybe I could try adding it sometime this week. Keep in mind the pure go implementation could really use some use and load testing to make sure it does what it says it does. DO NOT USE THE PURE GO FOR REALLY IMPORTANT DATA STORAGE YET!

Here's fatfs's seek: https://github.com/abbrev/fatfs/blob/b11f08931929e5f2f1fe8a3a2c0bd16d222b5625/source/ff.c#L4435-L4589

bgould commented 8 months ago

My opinion would be to add io.Seeker to tinyfs.File and stub out the method to start to always return a "Not Implemented" error or something similar. Probably I could work on an actual implementation and have it ready by the end of this weekend.

bgould commented 8 months ago

For the pure Go implementation I think we could also have another package under this repo ... maybe call it patfs ;)

bgould commented 8 months ago

@deadprogram added the io.Seeker interface and preliminary support for the Seek() method in fatfs (currently only supports seeking from the start of the file) - https://github.com/tinygo-org/tinyfs/pull/20