2019-08-17 23:26:17 +02:00
|
|
|
#pragma once
|
|
|
|
#include "StreamingMsgPackEncoder.h"
|
|
|
|
#include <FS.h>
|
|
|
|
|
|
|
|
|
|
|
|
class SpiffsStorageWriter {
|
|
|
|
public:
|
|
|
|
SpiffsStorageWriter(const String &fileName) :
|
|
|
|
f_(SPIFFS.open(fileName, "w")),
|
2019-09-10 22:05:28 +02:00
|
|
|
encoder_(&f_),
|
|
|
|
fileName_(fileName)
|
|
|
|
{
|
|
|
|
bool success = f_;
|
|
|
|
Serial.println(success);
|
|
|
|
}
|
|
|
|
~SpiffsStorageWriter() {
|
|
|
|
f_.close();
|
|
|
|
Serial.println(fileName_);
|
|
|
|
Serial.println(SPIFFS.exists(fileName_));
|
|
|
|
}
|
2019-08-17 23:26:17 +02:00
|
|
|
StreamingMsgPackEncoder<File> &encoder() { return encoder_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
File f_;
|
|
|
|
StreamingMsgPackEncoder<File> encoder_;
|
2019-09-10 22:05:28 +02:00
|
|
|
String fileName_;
|
2019-08-17 23:26:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class SpiffsStorageReader
|
|
|
|
{
|
|
|
|
public:
|
2019-08-22 21:33:36 +02:00
|
|
|
SpiffsStorageReader(const String &fileName) :
|
2020-05-16 12:33:53 +02:00
|
|
|
f_(SPIFFS.open(fileName, "r"))
|
2019-08-17 23:26:17 +02:00
|
|
|
{}
|
2019-09-10 22:05:28 +02:00
|
|
|
~SpiffsStorageReader() {
|
|
|
|
f_.close();
|
|
|
|
}
|
2019-08-17 23:26:17 +02:00
|
|
|
|
|
|
|
uint32_t readBytes(char *buffer, size_t length) {
|
|
|
|
return f_.readBytes(buffer, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool seek(uint32_t pos) {
|
|
|
|
return f_.seek(pos);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
File f_;
|
|
|
|
};
|