swimtracker-firmware/lib/session/SpiffsStorage.h

52 lines
1.1 KiB
C
Raw Normal View History

#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)
{
Serial.println("Opened file for writing successful?");
bool success = f_;
Serial.println(success);
}
~SpiffsStorageWriter() {
f_.close();
Serial.print("Closing file: ");
Serial.println(fileName_);
Serial.print("File exists: ");
Serial.println(SPIFFS.exists(fileName_));
}
StreamingMsgPackEncoder<File> &encoder() { return encoder_; }
private:
File f_;
StreamingMsgPackEncoder<File> encoder_;
2019-09-10 22:05:28 +02:00
String fileName_;
};
class SpiffsStorageReader
{
public:
2019-08-22 21:33:36 +02:00
SpiffsStorageReader(const String &fileName) :
f_(SPIFFS.open(fileName, "w"))
{}
2019-09-10 22:05:28 +02:00
~SpiffsStorageReader() {
f_.close();
}
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_;
};