Skip to content

Commit

Permalink
add util to get file size (#399)
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand authored Jan 8, 2025
1 parent d770216 commit 9f004b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/odr/internal/util/file_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

namespace odr::internal::util {

std::size_t file::size(const std::string &path) {
std::ifstream in(path, std::ios::binary | std::ios::ate);
if (!in.is_open() || in.fail()) {
throw FileNotFound();
}
return in.tellg();
}

std::string file::read(const std::string &path) {
std::ifstream in(path);
if (!in.is_open() || in.fail()) {
Expand Down
4 changes: 4 additions & 0 deletions src/odr/internal/util/file_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
#include <string>

namespace odr::internal::util::file {

std::size_t size(const std::string &path);

std::string read(const std::string &path);

} // namespace odr::internal::util::file

0 comments on commit 9f004b7

Please sign in to comment.