16 static constexpr uint8_t GZ_HEADER[3] = { 0x1F, 0x8B, 0x08 };
17 static constexpr uint8_t ZIP_HEADER[4] = { 0x50, 0x4B, 0x03, 0x04 };
19 std::unique_ptr<FileBase> file = std::make_unique<LocalFile>(std::move(
filename), mode);
20 if (file->getSize() >= 4) {
24 if (memcmp(buf, GZ_HEADER, 3) == 0) {
25 file = std::make_unique<GZFileAdapter>(std::move(file));
26 }
else if (memcmp(buf, ZIP_HEADER, 4) == 0) {
27 file = std::make_unique<ZipFileAdapter>(std::move(file));
31 checked_cast<LocalFile*>(file.get())->preCacheFile();
39 : file(init(std::move(
filename), mode))
69 : file(std::move(other.file))
74 : file(std::move(file_))
82 file = std::move(other.file);
93 file->read(buffer, num);
98 file->write(buffer, num);
113 return file->getSize();
123 return file->getPos();
128 return file->truncate(
size);
138 return file->getURL();
141 std::string File::getLocalReference()
const
143 return file->getLocalReference();
148 std::string_view orig = file->getOriginalName();
149 return !orig.empty() ? orig :
getURL();
154 return file->isReadOnly();
159 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(void *buffer, size_t num)
Read from 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.
void write(const void *buffer, size_t num)
Write to file.
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 const char *const filename
size_t size(std::string_view utf8)