-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #539 from openzim/counter_metadata
Counter metadata
- Loading branch information
Showing
8 changed files
with
164 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2021 Matthieu Gautier <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301, USA. | ||
*/ | ||
|
||
#include "counterHandler.h" | ||
#include "creatordata.h" | ||
|
||
#include <zim/writer/contentProvider.h> | ||
#include <zim/blob.h> | ||
|
||
using namespace zim::writer; | ||
|
||
CounterHandler::CounterHandler(CreatorData* data) | ||
: mp_creatorData(data) | ||
{} | ||
|
||
CounterHandler::~CounterHandler() = default; | ||
|
||
void CounterHandler::start() { | ||
} | ||
|
||
void CounterHandler::stop() { | ||
} | ||
|
||
Dirent* CounterHandler::createDirent() const { | ||
return mp_creatorData->createDirent('M', "Counter", "text/plain", ""); | ||
} | ||
|
||
std::unique_ptr<ContentProvider> CounterHandler::getContentProvider() const { | ||
std::stringstream ss; | ||
bool first = true; | ||
for(auto pair: m_mimetypeCounter) { | ||
if (! first) { | ||
ss << ";"; | ||
} | ||
ss << pair.first << "=" << pair.second; | ||
first = false; | ||
} | ||
return std::unique_ptr<ContentProvider>(new StringProvider(ss.str())); | ||
} | ||
|
||
void CounterHandler::handle(Dirent* dirent, const Hints& hints) | ||
{ | ||
} | ||
|
||
void CounterHandler::handle(Dirent* dirent, std::shared_ptr<Item> item) | ||
{ | ||
if (dirent->getNamespace() != 'C') { | ||
return; | ||
} | ||
auto mimetype = item->getMimeType(); | ||
if (mimetype.empty()) { | ||
return; | ||
} | ||
m_mimetypeCounter[mimetype] += 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2021 Matthieu Gautier <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301, USA. | ||
*/ | ||
|
||
#ifndef OPENZIM_LIBZIM_COUNTER_HANDLER_H | ||
#define OPENZIM_LIBZIM_COUNTER_HANDLER_H | ||
|
||
#include "handler.h" | ||
|
||
#include <map> | ||
|
||
namespace zim { | ||
namespace writer { | ||
|
||
|
||
class CounterHandler : public DirentHandler { | ||
public: | ||
typedef std::map<std::string, entry_index_type> Counter; | ||
|
||
explicit CounterHandler(CreatorData* data); | ||
virtual ~CounterHandler(); | ||
|
||
void start() override; | ||
void stop() override; | ||
bool isCompressible() override { return true; } | ||
std::unique_ptr<ContentProvider> getContentProvider() const override; | ||
void handle(Dirent* dirent, std::shared_ptr<Item> item) override; | ||
void handle(Dirent* dirent, const Hints& hints) override; | ||
|
||
private: | ||
Dirent* createDirent() const override; | ||
CreatorData* mp_creatorData; | ||
Counter m_mimetypeCounter; | ||
}; | ||
|
||
} | ||
} | ||
|
||
#endif // OPENZIM_LIBZIM_COUNTER_HANDLER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters