Extract EPUB TOC into temp file before parsing (#85)

## Summary

* Extract EPUB TOC into temp file before parsing
* Streaming ZIP -> XML parser uses up a lot of memory as we're
allocating inflation buffers while also holding a few copies of the
buffer in different forms
* Instead, but streaming the inflated file down to the SD card (like we
do for HTML parsing, we can lower memory usage)

## Additional Context

* This should help with
https://github.com/daveallie/crosspoint-reader/issues/60 and
https://github.com/daveallie/crosspoint-reader/issues/10. It won't
remove those class of issues completely, but will allow for many more
books to be opened.
This commit is contained in:
Dave Allie
2025-12-21 17:08:34 +11:00
committed by GitHub
parent 0d32d21d75
commit f264efdb12
4 changed files with 31 additions and 16 deletions

View File

@@ -2,12 +2,9 @@
#include <string>
class EpubTocEntry {
public:
struct EpubTocEntry {
std::string title;
std::string href;
std::string anchor;
int level;
EpubTocEntry(std::string title, std::string href, std::string anchor, const int level)
: title(std::move(title)), href(std::move(href)), anchor(std::move(anchor)), level(level) {}
uint8_t level;
};

View File

@@ -155,7 +155,7 @@ void XMLCALL TocNcxParser::endElement(void* userData, const XML_Char* name) {
}
// Push to vector
self->toc.emplace_back(self->currentLabel, href, anchor, self->currentDepth);
self->toc.push_back({std::move(self->currentLabel), std::move(href), std::move(anchor), self->currentDepth});
// Clear them so we don't re-add them if there are weird XML structures
self->currentLabel.clear();

View File

@@ -17,7 +17,7 @@ class TocNcxParser final : public Print {
std::string currentLabel;
std::string currentSrc;
size_t currentDepth = 0;
uint8_t currentDepth = 0;
static void startElement(void* userData, const XML_Char* name, const XML_Char** atts);
static void characterData(void* userData, const XML_Char* s, int len);