osrm-backend/include/util/mmap_tar.hpp

42 lines
1005 B
C++
Raw Normal View History

2018-03-22 11:40:57 -04:00
#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::util
2018-03-22 11:40:57 -04:00
{
using DataRange = std::pair<const char *, const char *>;
using DataMap = std::unordered_map<std::string, DataRange>;
inline DataMap mmapTarFile(const std::filesystem::path &path,
2018-03-22 11:40:57 -04:00
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;
}
2022-12-20 12:00:11 -05:00
} // namespace osrm::util
2018-03-22 11:40:57 -04:00
#endif