Page 1 of 1

Directly read n-th line in a file in SPIFFS

Posted: Sun Dec 26, 2021 12:17 am
by lesept
Hi
Is it possible to access directly a given line of a file stored in SPIFFS, I mean without reading all the lines before from the beginning of the file ? Thanks

Re: Directly read n-th line in a file in SPIFFS

Posted: Sun Dec 26, 2021 2:46 am
by ESP_Sprite
Not without help (and it's generally impossible, independent on the file system). Only way would be to index a file first, that is, scan through it and record at which position in the file every line begins, so you can later refer to that info and immediately go to the correct position.

Re: Directly read n-th line in a file in SPIFFS

Posted: Sun Dec 26, 2021 11:20 pm
by lesept
Thanks for your answer. I think this is exactly my case.
My file would be made of several lines (around 2000) each of which is made of 197 bytes.
So it's easy to know the exact place of each lines.

How can I then access for example the 200th line?

Re: Directly read n-th line in a file in SPIFFS

Posted: Mon Dec 27, 2021 1:34 am
by ESP_Sprite
I think you would use myfile.seek(line_number*197) to go to the correct position then.

Re: Directly read n-th line in a file in SPIFFS

Posted: Mon Dec 27, 2021 4:14 pm
by lesept
Thanks. Which library does this? LittleFS, SPIFFS?

Edit: Never mind, it seems it exists in both...
Thanks again, and Happy New Year! :D