Structure Description: File#
The File structure is a generic wrapper around a std::fstream with added utility functions to enable Big Endian read writes as most systems nowadays are in Little Endian byte order
-
struct File#
Thread-safe read and write by using a std::mutex to block any reading operations.
Public Functions
-
void read(std::span<uint8_t> buffer)#
Read n bytes from the file into the input buffer, make sure the buffer is properly allocated before running the function
-
void readFromOffset(std::span<uint8_t> buffer, const uint64_t offset)#
Read a specified number of bytes using a memory mapped file representation meaning this function is safe to call from any thread. This does not move around the internal offset marker unlike setOffsetAndRead.
-
void write(std::span<uint8_t> buffer)#
Write n bytes to the file from the input span.
-
void skip(int64_t size)#
Skip n bytes in the file and increment our position marker, checks if the offset is possible or if it would exceed the file size. Note: this is a uint64_t so skipping backwards is legal
-
inline uint64_t getOffset() const#
Return the current offset from the file start.
-
void setOffset(const uint64_t offset)#
Set the current offset to the specified value, checks if the offset is possible or if it would exceed the file size
-
void setOffsetAndRead(char *buffer, const uint64_t offset, const uint64_t size)#
Set the offset and read into a buffer using a singular lock. Use this if you need to skip to a section and read it in a multithreaded environment
-
inline uint64_t getSize() const noexcept#
Return the total size of the document.
-
inline std::filesystem::path getPath() const noexcept#
Return the path of the file associated with the File object.
-
File(std::filesystem::path file, const FileParams params = FileParams())#
Initialize our File object from a path on disk. If doRead is true the file is only open for reading while if we set it to false it is only open for writing
-
struct FileParams#
-
void read(std::span<uint8_t> buffer)#