11 template<
typename Ptr> [[nodiscard]]
const std::string&
operator()(
const Ptr& p)
const {
16 GetURLFromDecompressed,
XXHasher> decompressCache;
20 : file(
std::move(file_))
27 auto it = decompressCache.find(
getURL());
28 assert(it !=
end(decompressCache));
29 assert(it->get() == decompressed);
31 if ((*it)->useCount == 0) {
33 decompressCache.erase(it);
38void CompressedFileAdapter::decompress()
40 if (decompressed)
return;
42 const std::string& url =
getURL();
43 auto it = decompressCache.find(url);
44 if (it ==
end(decompressCache)) {
45 auto d = std::make_unique<Decompressed>();
46 decompress(*file, *d);
49 it = decompressCache.insert_noDuplicateCheck(std::move(d));
52 decompressed = it->get();
61 if (decompressed->
size < (pos + buffer.size())) {
64 const auto& buf = decompressed->
buf;
65 ranges::copy(std::span{&buf[pos], buffer.size()}, buffer);
71 throw FileException(
"Writing to compressed files not yet supported");
77 return { decompressed->
buf.
data(), decompressed->
size };
88 return decompressed->
size;
103 throw FileException(
"Truncating compressed files not yet supported.");
113 return file ? file->getURL() : decompressed->
cachedURL;
129 return file ? file->getModificationDate()
void read(std::span< uint8_t > buffer) final
std::string_view getOriginalName() final
virtual void decompress(FileBase &file, Decompressed &decompressed)=0
std::span< const uint8_t > mmap() final
void truncate(size_t size) final
bool isReadOnly() const final
void write(std::span< const uint8_t > buffer) final
~CompressedFileAdapter() override
const std::string & getURL() const final
CompressedFileAdapter(std::unique_ptr< FileBase > file)
void seek(size_t pos) final
time_t getModificationDate() final
const T * data() const
Returns pointer to the start of the memory buffer.
This file implemented 3 utility functions:
constexpr auto copy(InputRange &&range, OutputIter out)
time_t cachedModificationDate
const std::string & operator()(const Ptr &p) const
constexpr auto end(const zstring_view &x)