/* * GzipPostProcessing.cc * * Created on: 25 sept. 2013 * Author: CS */ #include "GzipPostProcessing.hh" #include "GzipNode.hh" #include "PostProcessingRegistry.hh" #include #include #include #include #include #include #include #include namespace postprocessing { const std::string GzipPostProcessing::EXTENSION = ".gz"; /** * Self-registering to post-processing factory */ std::string GzipPostProcessing::_key = PostProcessingRegistry::getInstance().addElement(EXTENSION, new GzipPostProcessing()); GzipPostProcessing::GzipPostProcessing() : PostProcessing() { } GzipPostProcessing::~GzipPostProcessing() { } /** * Applies post-processing. */ void GzipPostProcessing::apply(PostProcessingAble* pOutput) { _outputDestination = pOutput->getDestination(); for (auto file : pOutput->getOutputs()) { _files.push_back(gzip(file, pOutput->getDestination())); } } std::string GzipPostProcessing::gzip(std::string& pFile, const std::string& pOutDir) { std::string outFile = pFile + EXTENSION; if (!pOutDir.empty()) { boost::filesystem::path filePath(pFile); outFile = pOutDir + "/" + filePath.filename().string() + EXTENSION; } std::ofstream file(outFile, std::ios_base::out | std::ios_base::binary); std::ifstream in(pFile, std::ios_base::in); boost::iostreams::filtering_streambuf out; out.push(boost::iostreams::gzip_compressor()); out.push(file); boost::iostreams::copy(in, out); file.close(); boost::filesystem::path path(pFile); boost::filesystem::remove(path); return outFile; } /** * Registers related node and process. */ void GzipPostProcessing::registerChildList( std::map>& childList) { childList["gzip"] = boost::shared_ptr( new GzipNode()); } } /* namespace postprocessing */