diff --git a/lib/libfnd/include/fnd/io.h b/lib/libfnd/include/fnd/io.h index 7318126..d5ace2a 100644 --- a/lib/libfnd/include/fnd/io.h +++ b/lib/libfnd/include/fnd/io.h @@ -6,6 +6,7 @@ namespace fnd { namespace io { + size_t getFileSize(const std::string& path); void readFile(const std::string& path, MemoryBlob& blob); void readFile(const std::string& path, size_t offset, size_t len, MemoryBlob& blob); void writeFile(const std::string& path, const MemoryBlob& blob); diff --git a/lib/libfnd/source/io.cpp b/lib/libfnd/source/io.cpp index 0c2ef08..816190f 100644 --- a/lib/libfnd/source/io.cpp +++ b/lib/libfnd/source/io.cpp @@ -1,10 +1,22 @@ #include +#include using namespace fnd; static const std::string kModuleName = "IO"; static const size_t kBlockSize = 0x100000; +size_t io::getFileSize(const std::string& path) +{ + std::ifstream f; + f.open(path, std::ios_base::binary | std::ios_base::in); + if (!f.good() || f.eof() || !f.is_open()) { return 0; } + f.seekg(0, std::ios_base::beg); + std::ifstream::pos_type begin_pos = f.tellg(); + f.seekg(0, std::ios_base::end); + return static_cast(f.tellg() - begin_pos); +} + void io::readFile(const std::string& path, MemoryBlob & blob) { FILE* fp;