diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-04-02 09:15:30 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-04-02 09:15:30 +0100 |
commit | 21a147c3c1c2fad2819fe76becab320c51eb131f (patch) | |
tree | 9114123be1d9165a199d8b27af8f9b4e00333e71 /src/io_manager.cpp | |
download | YAGE-21a147c3c1c2fad2819fe76becab320c51eb131f.tar.gz YAGE-21a147c3c1c2fad2819fe76becab320c51eb131f.zip |
Adding initial files
Diffstat (limited to 'src/io_manager.cpp')
-rw-r--r-- | src/io_manager.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/io_manager.cpp b/src/io_manager.cpp new file mode 100644 index 00000000..106dd248 --- /dev/null +++ b/src/io_manager.cpp @@ -0,0 +1,27 @@ +#include "io_manager.hpp" + +#include <fstream> +#include <stdexcept> + +bool IoManager::readFileToBuffer(const std::string &file_path, std::vector<unsigned char> &buffer) +{ + std::ifstream file(file_path, std::ios::binary); + if(!file.is_open()) + throw std::runtime_error("Could not open '"+file_path+"'"); + + // seek to the end + file.seekg(0, std::ios::end); + + // get the file size + int file_size = file.tellg(); + file.seekg(0, std::ios::beg); + + // reduce file size by header bytes + file_size -= file.tellg(); + + buffer.resize(file_size); + file.read((char *)&buffer[0], file_size); + file.close(); + + return true; +} |