refactor: Add AutoFile::size

This commit is contained in:
Fabian Jahr
2024-09-19 17:36:19 +02:00
parent ec0f75862e
commit b7af960eb8
5 changed files with 24 additions and 6 deletions

View File

@@ -57,6 +57,20 @@ int64_t AutoFile::tell()
return *m_position;
}
int64_t AutoFile::size()
{
if (IsNull()) {
throw std::ios_base::failure("AutoFile::size: file handle is nullptr");
}
// Temporarily save the current position
int64_t current_pos = tell();
seek(0, SEEK_END);
int64_t file_size = tell();
// Restore the original position
seek(current_pos, SEEK_SET);
return file_size;
}
void AutoFile::read(std::span<std::byte> dst)
{
if (detail_fread(dst) != dst.size()) {