1#ifndef BYTEME_RAW_FILE_READER_HPP
2#define BYTEME_RAW_FILE_READER_HPP
11#include "SelfClosingFILE.hpp"
12#include "check_buffer_size.hpp"
54 my_buffer(check_buffer_size(options.buffer_size))
56 set_optional_bufsiz(my_file, options.
bufsiz);
65 auto& handle = my_file.handle;
66 my_read = std::fread(my_buffer.data(),
sizeof(
unsigned char), my_buffer.size(), handle);
68 if (my_read < my_buffer.size()) {
69 if (std::feof(handle)) {
72 throw std::runtime_error(
"failed to read raw binary file (fread error " + std::to_string(std::ferror(handle)) +
")");
79 const unsigned char*
buffer()
const {
80 return my_buffer.data();
88 SelfClosingFILE my_file;
89 std::vector<unsigned char> my_buffer;
90 std::size_t my_read = 0;
Read bytes from a file, usually text.
Definition RawFileReader.hpp:46
bool load()
Definition RawFileReader.hpp:60
RawFileReader(const char *path, const RawFileReaderOptions &options)
Definition RawFileReader.hpp:52
std::size_t available() const
Definition RawFileReader.hpp:83
const unsigned char * buffer() const
Definition RawFileReader.hpp:79
Virtual class for reading bytes from a source.
Definition Reader.hpp:17
Simple byte readers and writers.
Options for the RawFileReader constructor.
Definition RawFileReader.hpp:25
std::optional< unsigned > bufsiz
Definition RawFileReader.hpp:37
std::size_t buffer_size
Definition RawFileReader.hpp:30