SPIFFS file wrong dimension!
Posted: Tue Jul 12, 2016 9:44 am
I am using SPIFFS file system for logging data.
Sometimes when I re open an existing file a find a wrong file length:
More precisely :
I open this way:
if (SPIFFS.exists("/weather.log"))
wfile = SPIFFS.open("/weather.log", "r+");
else
wfile = SPIFFS.open("/weather.log", "w+");
if (!wfile) {
Serial.println("Cannot open weather.log"); return 0;
}
...if I read the file sequentially a find the EOF char before I get to the position defined by the end of the file:
file.seek(0,SeekEnd);
long EndOfFilePosition=file.position();
If I read sequentially this way:
while( file.available()) file.read();
The program run forever!
If I try to append to this file ....all the record appended are lost!
There is any way to avoid this error end to recover the file with the wrong length?
Sometimes when I re open an existing file a find a wrong file length:
More precisely :
I open this way:
if (SPIFFS.exists("/weather.log"))
wfile = SPIFFS.open("/weather.log", "r+");
else
wfile = SPIFFS.open("/weather.log", "w+");
if (!wfile) {
Serial.println("Cannot open weather.log"); return 0;
}
...if I read the file sequentially a find the EOF char before I get to the position defined by the end of the file:
file.seek(0,SeekEnd);
long EndOfFilePosition=file.position();
If I read sequentially this way:
while( file.available()) file.read();
The program run forever!
If I try to append to this file ....all the record appended are lost!
There is any way to avoid this error end to recover the file with the wrong length?