2024-05-31 22:59:00 -04:00
|
|
|
#ifndef RFL_IO_LOAD_BYTES_HPP_
|
|
|
|
#define RFL_IO_LOAD_BYTES_HPP_
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "../Result.hpp"
|
|
|
|
|
|
|
|
namespace rfl {
|
2024-06-08 14:10:59 -04:00
|
|
|
namespace io {
|
2024-05-31 22:59:00 -04:00
|
|
|
|
2024-06-08 14:10:59 -04:00
|
|
|
inline Result<std::vector<char>> load_bytes(const std::string& _fname) {
|
|
|
|
std::ifstream input(_fname, std::ios::binary);
|
|
|
|
if (input.is_open()) {
|
|
|
|
std::istreambuf_iterator<char> begin(input), end;
|
|
|
|
const auto bytes = std::vector<char>(begin, end);
|
|
|
|
input.close();
|
|
|
|
return bytes;
|
|
|
|
} else {
|
|
|
|
return rfl::Error("File '" + _fname + "' not found!");
|
|
|
|
}
|
|
|
|
}
|
2024-05-31 22:59:00 -04:00
|
|
|
|
2024-06-08 14:10:59 -04:00
|
|
|
} // namespace io
|
|
|
|
} // namespace rfl
|
2024-05-31 22:59:00 -04:00
|
|
|
|
|
|
|
#endif
|