Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
LittleFsFileReader.cpp
Go to the documentation of this file.
2#include <string>
3
5 : lfs(lfs) {}
6
7bool LittleFsFileReader::open(const std::string &path)
8{
9 if (!lfs)
10 return false;
11 isOpen = (lfs_file_open(lfs, &file, path.c_str(), LFS_O_RDONLY) == 0);
12 if (!isOpen)
13 {
14 return false;
15 }
16 return isOpen;
17}
18
23
24bool LittleFsFileReader::readLine(char *outLine, size_t maxLen)
25{
26 if (!isOpen || maxLen == 0)
27
28 return false;
29
30 size_t count = 0;
31 uint8_t ch;
32 int result;
33
34 while (count < maxLen - 1)
35 {
36 result = lfs_file_read(lfs, &file, &ch, 1);
37
38 if (result <= 0)
39 break;
40 if (ch == '\n')
41 break;
42 if (ch != '\r')
43 {
44 outLine[count++] = static_cast<char>(ch);
45 }
46 }
47
48 if (count == 0 && result <= 0)
49 return false;
50
51 outLine[count] = '\0';
52 return true;
53}
54
56{
57 if (isOpen) {
58 lfs_file_close(lfs, &file);
59 isOpen = false;
60 }
61}
bool open(const std::string &path)
Opens a file for reading.
void close() override
Close the file and release resources.
bool readLine(char *outLine, size_t maxLen)
Reads a single line into the provided buffer.