Class Reader¶
Defined in File reader.h
Class Documentation¶
-
class
kiwix
::
Reader
¶ Public Functions
-
explicit
Reader
(const string zimFilePath)¶ Create a Reader to read a zim file specified by zimFilePath.
- Parameters
zimFilePath – The path to the zim file to read. The zim file can be splitted (.zimaa, .zimab, …). In this case, the file path must still point to the unsplitted path as if the file were not splitted (.zim extesion).
Create a Reader to read a zim file given by the Archive.
- Parameters
archive – The shared pointer to the Archive object.
-
explicit
Reader
(int fd)¶
-
Reader
(int fd, zim::offset_type offset, zim::size_type size)¶
-
~Reader
() = default¶
-
unsigned int
getArticleCount
() const¶ Get the number of “displayable” entries in the zim file.
- Returns
If the zim file has a /M/Counter metadata, return the number of entries with the ‘text/html’ MIMEtype specified in the metadata. Else return the number of entries in the ‘A’ namespace.
-
unsigned int
getMediaCount
() const¶ Get the number of media in the zim file.
- Returns
If the zim file has a /M/Counter metadata, return the number of entries with the ‘image/jpeg’, ‘image/gif’ and ‘image/png’ in the metadata. Else return the number of entries in the ‘I’ namespace.
-
unsigned int
getGlobalCount
() const¶ Get the number of all entries in the zim file.
- Returns
Return the number of all the entries, whatever their MIMEtype or their namespace.
-
string
getZimFilePath
() const¶ Get the path of the zim file.
- Returns
the path of the zim file as given in the constructor.
-
string
getId
() const¶ Get the Id of the zim file.
- Returns
The uuid stored in the zim file.
-
Entry
getRandomPage
() const¶ Get a random page.
- Returns
A random Entry. The entry is picked from all entries in the ‘A’ namespace. The main entry is excluded from the potential results.
-
Entry
getMainPage
() const¶ Get the entry of the main page.
- Returns
Entry of the main page as specified in the zim file.
-
bool
getMetadata
(const string &name, string &value) const¶ Get the content of a metadata.
- Parameters
name – [in] The name of the metadata.
value – [out] The value will be set to the content of the metadata.
- Returns
True if it was possible to get the content of the metadata.
-
string
getName
() const¶ Get the name of the zim file.
- Returns
The name of the zim file as specified in the zim metadata.
-
string
getTitle
() const¶ Get the title of the zim file.
- Returns
The title of zim file as specified in the zim metadata. If no title has been set, return a title computed from the file path.
-
string
getCreator
() const¶ Get the creator of the zim file.
- Returns
The creator of the zim file as specified in the zim metadata.
-
string
getPublisher
() const¶ Get the publisher of the zim file.
- Returns
The publisher of the zim file as specified in the zim metadata.
-
string
getDate
() const¶ Get the date of the zim file.
- Returns
The date of the zim file as specified in the zim metadata.
-
string
getDescription
() const¶ Get the description of the zim file.
- Returns
The description of the zim file as specified in the zim metadata. If no description has been set, return the subtitle.
-
string
getLongDescription
() const¶ Get the long description of the zim file.
- Returns
The long description of the zim file as specifed in the zim metadata.
-
string
getLanguage
() const¶ Get the language of the zim file.
- Returns
The language of the zim file as specified in the zim metadata.
-
string
getLicense
() const¶ Get the license of the zim file.
- Returns
The license of the zim file as specified in the zim metadata.
-
string
getTags
(bool original = false) const¶ Get the tags of the zim file.
- Parameters
original – If true, return the original tags as specified in the zim metadata. Else, try to convert it to the new ‘normalized’ format.
- Returns
The tags of the zim file.
-
string
getTagStr
(const std::string &tagName) const¶ Get the value (as a string) of a specific tag.
According to https://wiki.openzim.org/wiki/Tags
- Throws
std::out_of_range – if the specified tag is not found.
- Returns
The value of the specified tag.
-
bool
getTagBool
(const std::string &tagName) const¶ Get the boolean value of a specific tag.
According to https://wiki.openzim.org/wiki/Tags
- Throws
std::out_of_range – if the specified tag is not found. std::domain_error if the value of the tag cannot be convert to bool.
- Returns
The boolean value of the specified tag.
-
string
getRelation
() const¶ Get the relations of the zim file.
- Returns
The relation of the zim file as specified in the zim metadata.
-
string
getFlavour
() const¶ Get the flavour of the zim file.
- Returns
The flavour of the zim file as specified in the zim metadata.
-
string
getSource
() const¶ Get the source of the zim file.
- Returns
The source of the zim file as specified in the zim metadata.
-
string
getScraper
() const¶ Get the scraper of the zim file.
- Returns
The scraper of the zim file as specified in the zim metadata.
-
bool
getFavicon
(string &content, string &mimeType) const¶ Get the favicon of the zim file.
- Parameters
content – [out] The content of the favicon.
mimeType – [out] The mimeType of the favicon.
- Returns
True if a favicon has been found.
-
Entry
getEntryFromPath
(const std::string &path) const¶ Get an entry associated to an path.
- Parameters
path – The path of the entry.
- Throws
NoEntry – If no entry correspond to the path.
- Returns
The entry.
-
Entry
getEntryFromEncodedPath
(const std::string &path) const¶ Get an entry associated to an url encoded path.
Equivalent to
getEntryFromPath(urlDecode(path));
- Parameters
path – The url encoded path.
- Throws
NoEntry – If no entry correspond to the path.
- Returns
The entry.
-
Entry
getEntryFromTitle
(const std::string &title) const¶ Get un entry associated to a title.
- Parameters
title – The title.
- Returns
The entry throw NoEntry If no entry correspond to the url.
-
bool
searchSuggestions
(const string &prefix, unsigned int suggestionsCount, const bool reset = true)¶ Search for entries with title starting with prefix (case sensitive).
Suggestions are stored in an internal vector and can be retrieved using
getNextSuggestion
method. This method is not thread safe and is deprecated. Use : bool searchSuggestions(const string& prefix, unsigned int suggestionsCount, SuggestionsList_t& results);- Parameters
prefix – The prefix to search.
suggestionsCount – How many suggestions to search for.
reset – If true, remove previous suggestions in the internal vector. If false, add suggestions to the internal vector (until internal vector size is suggestionCount (or no more suggestion))
- Returns
True if some suggestions have been added to the internal vector.
-
bool
searchSuggestions
(const string &prefix, unsigned int suggestionsCount, SuggestionsList_t &resuls)¶ Search for entries with title starting with prefix (case sensitive).
Suggestions are added to the
result
vector.- Parameters
prefix – The prefix to search.
suggestionsCount – How many suggestions to search for.
result – The vector where to store the suggestions.
- Returns
True if some suggestions have been added to the vector.
-
bool
searchSuggestionsSmart
(const string &prefix, unsigned int suggestionsCount)¶ Search for entries for the given prefix.
If the zim file has a internal fulltext index, the suggestions will be searched using it. Else the suggestions will be search using
searchSuggestions
while trying to be smart about case sensitivity (usinggetTitleVariants
).In any case, suggestions are stored in an internal vector and can be retrieved using
getNextSuggestion
method. The internal vector will be reset. This method is not thread safe and is deprecated. Use : bool searchSuggestionsSmart(const string& prefix, unsigned int suggestionsCount, SuggestionsList_t& results);- Parameters
prefix – The prefix to search for.
suggestionsCount – How many suggestions to search for.
-
bool
searchSuggestionsSmart
(const string &prefix, unsigned int suggestionsCount, SuggestionsList_t &results)¶ Search for entries for the given prefix.
If the zim file has a internal fulltext index, the suggestions will be searched using it. Else the suggestions will be search using
searchSuggestions
while trying to be smart about case sensitivity (usinggetTitleVariants
).In any case, suggestions are stored in an internal vector and can be retrieved using
getNextSuggestion
method. The internal vector will be reset.- Parameters
prefix – The prefix to search for.
suggestionsCount – How many suggestions to search for.
results – The vector where to store the suggestions
- Returns
True if some suggestions have been added to the results.
-
bool
pathExists
(const string &path) const¶ Check if the path exists in the zim file.
- Parameters
path – the path to check.
- Returns
True if the path exists in the zim file.
-
bool
hasFulltextIndex
() const¶ Check if the zim file has a embedded fulltext index.
- Returns
True if the zim file has a embedded fulltext index and is not split (else the fulltext is not accessible).
-
std::vector<std::string>
getTitleVariants
(const std::string &title) const¶ Get potential case title variations for a title.
- Parameters
title – a title.
- Returns
the list of variantions.
-
bool
getNextSuggestion
(string &title)¶ Get the next suggestion title.
- Parameters
title – [out] the title of the suggestion.
- Returns
True if title has been set.
-
bool
getNextSuggestion
(string &title, string &url)¶ Get the next suggestion title and url.
- Parameters
title – [out] the title of the suggestion.
url – [out] the url of the suggestion.
- Returns
True if title and url have been set.
-
bool
canCheckIntegrity
() const¶ Get if we can check zim file integrity (has a checksum).
- Returns
True if zim file have a checksum.
-
bool
isCorrupted
() const¶ Check is zim file is corrupted.
- Returns
True if zim file is corrupted.
-
unsigned int
getFileSize
() const¶ Return the total size of the zim file.
If zim file is split, return the sum of all parts’ size.
- Returns
Size of the size file is KiB.
-
zim::Archive *
getZimArchive
() const¶ Get the zim file handler.
- Returns
The libzim file handler.
Protected Attributes
-
std::shared_ptr<zim::Archive>
zimArchive
¶
-
std::string
zimFilePath
¶
-
SuggestionsList_t
suggestions
¶
-
SuggestionsList_t::iterator
suggestionsOffset
¶
-
explicit