mirror of
https://github.com/jakcron/nstool
synced 2024-11-14 09:46:39 +00:00
[fnd] Add fnd::io::getFileSize()
This commit is contained in:
parent
8a8fe7b0e8
commit
88bcc8ce6d
2 changed files with 13 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -1,10 +1,22 @@
|
|||
#include <fnd/io.h>
|
||||
#include <fstream>
|
||||
|
||||
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<size_t>(f.tellg() - begin_pos);
|
||||
}
|
||||
|
||||
void io::readFile(const std::string& path, MemoryBlob & blob)
|
||||
{
|
||||
FILE* fp;
|
||||
|
|
Loading…
Reference in a new issue