35#if UNIOT_USE_NVSFS == 1
38#elif UNIOT_USE_LITTLEFS == 1
40#define FileFS LittleFS
75 String normalizedPath = path;
76 if (!normalizedPath.startsWith(
"/")) {
77 normalizedPath =
"/" + normalizedPath;
87 sMounted =
FileFS.begin(
true);
103 if (!sInstancesCount) {
145#if UNIOT_USE_LITTLEFS != 1
171#ifdef UNIOT_USE_NVSFS
172 mData = file.getBytes();
174 mData = _readSmallFile(file);
237#ifndef UNIOT_USE_NVSFS
238 Bytes _readSmallFile(File &file) {
239 auto toRead = file.
size() - file.position();
241 Bytes data(
nullptr, toRead);
242 if (data.size() != toRead) {
247 auto countRead = data.fill([&file](uint8_t *buf,
size_t size) {
248 return file.readBytes(
reinterpret_cast<char *
>(buf), size);
250 data.prune(countRead);
261 static bool sMounted;
268 static unsigned int sInstancesCount;
#define FileFS
Definition Storage.h:44
size_t size() const
Gets the size of the byte array.
Definition Bytes.h:343
Storage(const String &path)
Constructs a Storage object for a specific file.
Definition Storage.h:74
String mPath
The file path where data is stored.
Definition Storage.h:212
void setPath(const String &path)
Sets the file path, ensuring it starts with "/".
Definition Storage.h:219
virtual bool clean()
Clears data and removes the file from the file system.
Definition Storage.h:189
Bytes mData
The byte array containing the data to be stored or the loaded data.
Definition Storage.h:205
virtual bool store()
Writes the current data to the file system.
Definition Storage.h:135
virtual bool restore()
Loads data from the file system into memory.
Definition Storage.h:165
virtual ~Storage()
Destructor.
Definition Storage.h:101
static void unmount()
Explicitly unmounts the filesystem.
Definition Storage.h:118
#define UNIOT_LOG_WARN(...)
Log an WARN level message Used for warnings about potentially problematic situations....
Definition Logger.h:294
#define UNIOT_LOG_WARN_IF(log_cond, log...)
Conditionally log an WARN level message Used for warnings about potentially problematic situations....
Definition Logger.h:302
#define UNIOT_LOG_ERROR(...)
Log an ERROR level message Used for critical errors that may prevent normal operation....
Definition Logger.h:273
#define UNIOT_LOG_DEBUG_IF(log_cond, log...)
Conditionally log an DEBUG level message Used for general information about system operation....
Definition Logger.h:348
Contains all classes and functions related to the Uniot Core.