Add tar file mmaping

This commit is contained in:
Patrick Niklaus
2018-03-22 15:40:57 +00:00
parent a52213c885
commit bde51a9ef5
2 changed files with 52 additions and 2 deletions
+44
View File
@@ -0,0 +1,44 @@
#ifndef OSRM_UTIL_MMAP_TAR_HPP
#define OSRM_UTIL_MMAP_TAR_HPP
#include "storage/tar.hpp"
#include "util/mmap_file.hpp"
#include <boost/iostreams/device/mapped_file.hpp>
#include <tuple>
#include <unordered_map>
namespace osrm
{
namespace util
{
using DataRange = std::pair<const char *, const char *>;
using DataMap = std::unordered_map<std::string, DataRange>;
inline DataMap mmapTarFile(const boost::filesystem::path &path,
boost::iostreams::mapped_file_source &region)
{
DataMap map;
storage::tar::FileReader reader{path, storage::tar::FileReader::VerifyFingerprint};
std::vector<storage::tar::FileReader::FileEntry> entries;
reader.List(std::back_inserter(entries));
auto raw_file = mmapFile<char>(path, region);
for (const auto &entry : entries)
{
auto begin = raw_file.data() + entry.offset;
auto end = begin + entry.size;
map[entry.name] = DataRange{begin, end};
}
return map;
}
}
}
#endif