MCPcopy Create free account
hub / github.com/BruceDevices/firmware / readSmallFile

Function readSmallFile

src/core/sd_functions.cpp:380–398  ·  view source on GitHub ↗

** Function name: readSmallFile ** Description: read a small (<3KB) file and return its contents as a single string ** on any error returns an empty string ***************************************************************************************/

Source from the content-addressed store, hash-verified

378** on any error returns an empty string
379***************************************************************************************/
380String readSmallFile(FS &fs, String filepath) {
381 String fileContent = "";
382 File file;
383
384 file = fs.open(filepath, FILE_READ);
385 if (!file) return "";
386
387 size_t fileSize = file.size();
388 if (fileSize > SAFE_STACK_BUFFER_SIZE || fileSize > ESP.getFreeHeap()) {
389 displayError("File is too big", true);
390 return "";
391 }
392 // TODO: if(psramFound()) -> use PSRAM instead
393
394 fileContent = file.readString();
395
396 file.close();
397 return fileContent;
398}
399
400/***************************************************************************************
401** Function name: readFile

Callers 4

md5FileFunction · 0.85
crc32FileFunction · 0.85
loopSDFunction · 0.85
readCallbackFunction · 0.85

Calls 3

displayErrorFunction · 0.85
sizeMethod · 0.80
closeMethod · 0.80

Tested by

no test coverage detected