/* * Author: Patrick-Christopher Mattulat * Company: Lynar Studios * E-Mail: webmaster@lynarstudios.com * Created: 2020-08-17 * Changed: 2023-05-16 * * */ #include #include #include #include using ls::std::core::Class; using ls::std::core::FileOperationException; using ls::std::core::type::byte_field; using ls::std::core::type::byte_type; using ls::std::io::File; using ls::std::io::FileExistenceEvaluator; using ls::std::io::FileReader; using std::ifstream; using std::string; FileReader::FileReader(const File &_file) : Class("FileReader"), file(_file) { FileExistenceEvaluator{_file.getAbsoluteFilePath()}.evaluate(); } FileReader::~FileReader() noexcept = default; byte_field FileReader::read() { ifstream inputStream{this->file.getAbsoluteFilePath(), ifstream::binary}; auto length = (int) this->file.getSize(); auto data = string(length, 'x'); inputStream.read(data.data(), length); if (inputStream.fail()) { throw FileOperationException{"operation: read"}; } inputStream.close(); return data; } void FileReader::reset(const File &_file) { FileExistenceEvaluator{_file.getAbsoluteFilePath()}.evaluate(); this->file = _file; }