1
0
mirror of https://github.com/Dejvino/lilybook.git synced 2024-09-28 01:43:37 +00:00
lilybook/main/TextReader.cpp
2020-01-31 20:54:19 +01:00

35 lines
743 B
C++

#include "TextReader.h"
#include "esp_log.h"
static const char *TAG = "TextReader";
TextReader::TextReader(FILE* file)
{
this->f = file;
}
void TextReader::close()
{
fclose(this->f);
}
size_t TextReader::read(long pos, char* text, size_t len)
{
if (this->f == NULL) {
ESP_LOGE(TAG, "File not opened.");
sprintf(text, "File could not be opened.");
return 0;
} else {
fseek(this->f, pos, SEEK_SET);
size_t read = fread(text, 1, len, this->f);
if (read > 0) {
ESP_LOGI(TAG, "Read content: %s", text);
} else {
ESP_LOGI(TAG, "End of file. Closing.");
fclose(this->f);
this->f = NULL;
}
return read;
}
}