Directly read n-th line in a file in SPIFFS

lesept
Posts: 38
Joined: Wed Jun 27, 2018 10:30 pm

Directly read n-th line in a file in SPIFFS

Postby lesept » Sun Dec 26, 2021 12:17 am

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

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Sun Dec 26, 2021 2:46 am

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.

lesept
Posts: 38
Joined: Wed Jun 27, 2018 10:30 pm

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

Postby lesept » Sun Dec 26, 2021 11:20 pm

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?

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Mon Dec 27, 2021 1:34 am

I think you would use myfile.seek(line_number*197) to go to the correct position then.

lesept
Posts: 38
Joined: Wed Jun 27, 2018 10:30 pm

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

Postby lesept » Mon Dec 27, 2021 4:14 pm

Thanks. Which library does this? LittleFS, SPIFFS?

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

Who is online

Users browsing this forum: No registered users and 59 guests