diff options
author | Roland Reichwein <mail@reichwein.it> | 2021-02-01 16:45:18 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2021-02-01 16:45:18 +0100 |
commit | f34a0aa3a2d46d349a41c0b28939176791c2efbe (patch) | |
tree | 663e5d5fd02cbb9b8f44cc502083f85b5b4d5c17 /src/file.cpp | |
parent | 611601ec36a5603bc9c94cdac9a307c4bb07c929 (diff) |
Implemented recode and validate tools
Diffstat (limited to 'src/file.cpp')
-rw-r--r-- | src/file.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/file.cpp b/src/file.cpp new file mode 100644 index 0000000..571a9f8 --- /dev/null +++ b/src/file.cpp @@ -0,0 +1,36 @@ +#include "file.h" + +#include <fstream> + +namespace fs = std::filesystem; + +using namespace std::string_literals; + +std::string unicode::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, '\0'); + file.read(reinterpret_cast<char*>(bytes.data()), fileSize); + + return bytes; + + } else { + throw std::runtime_error("Opening "s + filename.string() + " for reading"); + } +} + +void unicode::File::setFile(const fs::path& filename, const std::string& s) +{ + std::ofstream file(filename.string(), std::ios::out | std::ios::binary); + if (file.is_open()) { + file.write(s.data(), s.size()); + } else { + throw std::runtime_error("Opening "s + filename.string() + " for writing"); + } +} + |