From 5bc1f7bed536e0e936fd13fad45c49392b0bfff4 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Mon, 11 May 2020 12:24:04 +0200 Subject: Separated out routines to libcommon --- plugins/webbox/file.cpp | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 plugins/webbox/file.cpp (limited to 'plugins/webbox/file.cpp') diff --git a/plugins/webbox/file.cpp b/plugins/webbox/file.cpp deleted file mode 100644 index 47ab8be..0000000 --- a/plugins/webbox/file.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "file.h" - -#include - -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(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& data) -{ - File::setFile(filename, reinterpret_cast(data.data()), data.size()); -} - -- cgit v1.2.3