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();
240 char *buf = (
char *)malloc(toRead);
241 auto countRead = file.readBytes(buf, toRead);
242 const Bytes data((uint8_t *)buf, countRead);
253 static bool sMounted;
260 static unsigned int sInstancesCount;
#define FileFS
Definition Storage.h:44
size_t size() const
Gets the size of the byte array.
Definition Bytes.h:303
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:247
#define UNIOT_LOG_WARN_IF(log_cond, log...)
Conditionally log an WARN level message Used for warnings about potentially problematic situations....
Definition Logger.h:255
#define UNIOT_LOG_DEBUG_IF(log_cond, log...)
Conditionally log an DEBUG level message Used for general information about system operation....
Definition Logger.h:301
Contains all classes and functions related to the Uniot Core.