## Summary * Use single unified cache file for book spine, table of contents, and core metadata (title, author, cover image) * Use new temp item store file in OPF parsing to store items to be rescaned when parsing spine * This avoids us holding these items in memory * Use new toc.bin.tmp and spine.bin.tmp to build out partial toc / spine data as part of parsing content.opf and the NCX file * These files are re-read multiple times to ultimately build book.bin ## Additional Context * Spec for file format included below as an image * This should help with: * #10 * #60 * #99
47 lines
1.2 KiB
C++
47 lines
1.2 KiB
C++
#pragma once
|
|
#include <Print.h>
|
|
|
|
#include "Epub.h"
|
|
#include "expat.h"
|
|
|
|
class BookMetadataCache;
|
|
|
|
class ContentOpfParser final : public Print {
|
|
enum ParserState {
|
|
START,
|
|
IN_PACKAGE,
|
|
IN_METADATA,
|
|
IN_BOOK_TITLE,
|
|
IN_MANIFEST,
|
|
IN_SPINE,
|
|
};
|
|
|
|
const std::string& cachePath;
|
|
const std::string& baseContentPath;
|
|
size_t remainingSize;
|
|
XML_Parser parser = nullptr;
|
|
ParserState state = START;
|
|
BookMetadataCache* cache;
|
|
File tempItemStore;
|
|
std::string coverItemId;
|
|
|
|
static void startElement(void* userData, const XML_Char* name, const XML_Char** atts);
|
|
static void characterData(void* userData, const XML_Char* s, int len);
|
|
static void endElement(void* userData, const XML_Char* name);
|
|
|
|
public:
|
|
std::string title;
|
|
std::string tocNcxPath;
|
|
std::string coverItemHref;
|
|
|
|
explicit ContentOpfParser(const std::string& cachePath, const std::string& baseContentPath, const size_t xmlSize,
|
|
BookMetadataCache* cache)
|
|
: cachePath(cachePath), baseContentPath(baseContentPath), remainingSize(xmlSize), cache(cache) {}
|
|
~ContentOpfParser() override;
|
|
|
|
bool setup();
|
|
|
|
size_t write(uint8_t) override;
|
|
size_t write(const uint8_t* buffer, size_t size) override;
|
|
};
|