** Function name: readSmallFile ** Description: read a small (<3KB) file and return its contents as a single string ** on any error returns an empty string ***************************************************************************************/
| 378 | ** on any error returns an empty string |
| 379 | ***************************************************************************************/ |
| 380 | String 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 |
no test coverage detected