15[[nodiscard]]
static std::unique_ptr<FileBase> init(std::string filename,
File::OpenMode mode)
17 static constexpr std::array<uint8_t, 3> GZ_HEADER = {0x1F, 0x8B, 0x08};
18 static constexpr std::array<uint8_t, 4> ZIP_HEADER = {0x50, 0x4B, 0x03, 0x04};
20 std::unique_ptr<FileBase> file = std::make_unique<LocalFile>(std::move(filename), mode);
21 if (file->getSize() >= 4) {
22 std::array<uint8_t, 4> buf;
26 file = std::make_unique<GZFileAdapter>(std::move(file));
28 file = std::make_unique<ZipFileAdapter>(std::move(file));
32 checked_cast<LocalFile*>(file.get())->preCacheFile();
40 : file(init(
std::move(filename), mode))
45 :
File(filename.getResolved(), mode)
50 :
File(
std::move(filename).getResolved(), mode)
60 :
File(filename.getResolved(), mode)
65 :
File(
std::move(filename).getResolved(), mode)
70 : file(std::move(other.file))
75 : file(
std::move(file_))
83 file = std::move(other.file);
114 return file->getSize();
124 return file->getPos();
129 return file->truncate(size);
139 return file->getURL();
142std::string File::getLocalReference()
const
144 return file->getLocalReference();
149 std::string_view orig = file->getOriginalName();
150 return !orig.empty() ? orig :
getURL();
155 return file->isReadOnly();
160 return file->getModificationDate();
void close()
Close the current file.
void seek(size_t pos)
Move read/write pointer to the specified position.
bool isReadOnly() const
Check if this file is readonly.
std::span< const uint8_t > mmap()
Map file in memory.
File()
Create a closed file handle.
File & operator=(File &&other) noexcept
std::string_view getOriginalName()
Get Original filename for this object.
void read(std::span< uint8_t > buffer)
Read from file.
void write(std::span< const uint8_t > buffer)
Write to file.
time_t getModificationDate()
Get the date/time of last modification.
void truncate(size_t size)
Truncate file size.
size_t getSize()
Returns the size of this file.
size_t getPos()
Get the current position of the read/write pointer.
void munmap()
Unmap file from memory.
const std::string & getURL() const
Returns the URL of this file object.
void flush()
Force a write of all buffered data to disk.
This class represents a filename.
This file implemented 3 utility functions:
constexpr bool equal(InputRange1 &&range1, InputRange2 &&range2, Pred pred={}, Proj1 proj1={}, Proj2 proj2={})