diff options
author | Roland Reichwein <mail@reichwein.it> | 2023-01-03 09:31:51 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2023-01-03 09:31:51 +0100 |
commit | 2b6f8123e925e3be8ce7c04eccdd49fc728314a5 (patch) | |
tree | 78e86bb428b3bc821ae84d0f6abe86136356bd1a /libcommon/file.cpp | |
parent | 5581340f23b31114d33736c630de849898668f38 (diff) |
Separated out libcommon as libreichwein
Diffstat (limited to 'libcommon/file.cpp')
-rw-r--r-- | libcommon/file.cpp | 46 |
1 files changed, 0 insertions, 46 deletions
diff --git a/libcommon/file.cpp b/libcommon/file.cpp deleted file mode 100644 index 47ab8be..0000000 --- a/libcommon/file.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "file.h" - -#include <fstream> - -namespace fs = std::filesystem; - -using namespace std::string_literals; - -std::string File::getFile(const fs::path& filename) -{ - std::ifstream file(filename.string(), std::ios::in | std::ios::binary | std::ios::ate); - - if (file.is_open()) { - std::ifstream::pos_type fileSize = file.tellg(); - file.seekg(0, std::ios::beg); - - std::string bytes(fileSize, ' '); - file.read(reinterpret_cast<char*>(bytes.data()), fileSize); - - return bytes; - - } else { - throw std::runtime_error("Opening "s + filename.string() + " for reading"); - } -} - -void File::setFile(const fs::path& filename, const std::string& s) -{ - File::setFile(filename, s.data(), s.size()); -} - -void File::setFile(const fs::path& filename, const char* data, size_t size) -{ - std::ofstream file(filename.string(), std::ios::out | std::ios::binary); - if (file.is_open()) { - file.write(data, size); - } else { - throw std::runtime_error("Opening "s + filename.string() + " for writing"); - } -} - -void File::setFile(const fs::path& filename, const std::vector<uint8_t>& data) -{ - File::setFile(filename, reinterpret_cast<const char*>(data.data()), data.size()); -} - |