mirror of https://github.com/kiwix/libkiwix.git
+ better alloc memory
This commit is contained in:
parent
7a0aab3917
commit
2240b11224
|
@ -243,19 +243,17 @@ namespace kiwix {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::readBookFromPath(const string path, kiwix::Book &book) {
|
bool Manager::readBookFromPath(const string path, kiwix::Book &book) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
kiwix::Reader reader = kiwix::Reader(path);
|
kiwix::Reader *reader = new kiwix::Reader(path);
|
||||||
book.path = path;
|
book.path = path;
|
||||||
book.pathAbsolute = path;
|
book.pathAbsolute = path;
|
||||||
book.id = reader.getId();
|
book.id = reader->getId();
|
||||||
book.description = reader.getDescription();
|
book.description = reader->getDescription();
|
||||||
book.language = reader.getLanguage();
|
book.language = reader->getLanguage();
|
||||||
book.date = reader.getDate();
|
book.date = reader->getDate();
|
||||||
book.creator = reader.getCreator();
|
book.creator = reader->getCreator();
|
||||||
book.publisher = reader.getPublisher();
|
book.publisher = reader->getPublisher();
|
||||||
|
book.title = reader->getTitle();
|
||||||
book.title = reader.getTitle();
|
|
||||||
if (book.title.empty()) {
|
if (book.title.empty()) {
|
||||||
book.title = getLastPathElement(path);
|
book.title = getLastPathElement(path);
|
||||||
std::replace(book.title.begin(), book.title.end(), '_', ' ');
|
std::replace(book.title.begin(), book.title.end(), '_', ' ');
|
||||||
|
@ -264,22 +262,24 @@ namespace kiwix {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostringstream articleCountStream;
|
std::ostringstream articleCountStream;
|
||||||
articleCountStream << reader.getArticleCount();
|
articleCountStream << reader->getArticleCount();
|
||||||
book.articleCount = articleCountStream.str();
|
book.articleCount = articleCountStream.str();
|
||||||
|
|
||||||
std::ostringstream mediaCountStream;
|
std::ostringstream mediaCountStream;
|
||||||
mediaCountStream << reader.getMediaCount();
|
mediaCountStream << reader->getMediaCount();
|
||||||
book.mediaCount = mediaCountStream.str();
|
book.mediaCount = mediaCountStream.str();
|
||||||
|
|
||||||
ostringstream convert; convert << reader.getFileSize();
|
ostringstream convert; convert << reader->getFileSize();
|
||||||
book.size = convert.str();
|
book.size = convert.str();
|
||||||
|
|
||||||
string favicon;
|
string favicon;
|
||||||
string faviconMimeType;
|
string faviconMimeType;
|
||||||
if (reader.getFavicon(favicon, faviconMimeType)) {
|
if (reader->getFavicon(favicon, faviconMimeType)) {
|
||||||
book.favicon = base64_encode(reinterpret_cast<const unsigned char*>(favicon.c_str()), favicon.length());
|
book.favicon = base64_encode(reinterpret_cast<const unsigned char*>(favicon.c_str()), favicon.length());
|
||||||
book.faviconMimeType = faviconMimeType;
|
book.faviconMimeType = faviconMimeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete reader;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue