Skip to content

Instantly share code, notes, and snippets.

@DaleGia
Created June 10, 2020 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaleGia/294357ac8ca5d3f534db0b449d58f545 to your computer and use it in GitHub Desktop.
Save DaleGia/294357ac8ca5d3f534db0b449d58f545 to your computer and use it in GitHub Desktop.
ESPFlash: Open a file with a filename of “/lengthExample” and get the number of elements stored in the file with error checking.
/*
Open a file with a filename of “/lengthExample” and get the number of
elements stored in the file with error checking.
*/
ESPFlash<double> lengthExample("/lengthExample");
uint32_t numberOfElements = lengthExample.length();
/* The above code replaces the following SPIFFS implementation */
File file;
uint32_t sizeInBytes = 0;
uint32_t sizeInElements = 0;
SPIFFS.begin();
file = SPIFFS.open("/lengthExample", "r");
if(file)
{
sizeInBytes = file.size();
sizeInElements = sizeInBytes/sizeof(double);
}
file.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment