1#ifndef BYTEME_RAW_FILE_READER_HPP
2#define BYTEME_RAW_FILE_READER_HPP
9#include "SelfClosingFILE.hpp"
31 RawFileReader(
const char* path,
size_t buffer_size = 65536) : my_file(path,
"rb"), my_buffer(buffer_size) {}
45 auto& handle = my_file.handle;
46 my_read = std::fread(my_buffer.data(),
sizeof(
unsigned char), my_buffer.size(), handle);
48 if (my_read < my_buffer.size()) {
49 if (std::feof(handle)) {
52 throw std::runtime_error(
"failed to read raw binary file (fread error " + std::to_string(std::ferror(handle)) +
")");
59 const unsigned char*
buffer()
const {
60 return my_buffer.data();
68 SelfClosingFILE my_file;
69 std::vector<unsigned char> my_buffer;
Read bytes from a file, usually text.
Definition RawFileReader.hpp:25
RawFileReader(const char *path, size_t buffer_size=65536)
Definition RawFileReader.hpp:31
RawFileReader(const std::string &path, size_t buffer_size=65536)
Definition RawFileReader.hpp:37
bool load()
Definition RawFileReader.hpp:40
size_t available() const
Definition RawFileReader.hpp:63
const unsigned char * buffer() const
Definition RawFileReader.hpp:59
Virtual class for reading bytes from a source.
Definition Reader.hpp:15
Simple byte readers and writers.