1#ifndef BYTEME_RAW_FILE_WRITER_HPP
2#define BYTEME_RAW_FILE_WRITER_HPP
11#include "SelfClosingFILE.hpp"
46 set_optional_bufsiz(my_file, options.
bufsiz);
52 void write(
const unsigned char* buffer, std::size_t n) {
53 std::size_t ok = std::fwrite(buffer,
sizeof(
unsigned char), n, my_file.handle);
55 throw std::runtime_error(
"failed to write raw binary file (fwrite error " + std::to_string(std::ferror(my_file.handle)) +
")");
52 void write(
const unsigned char* buffer, std::size_t n) {
…}
60 if (std::fclose(my_file.handle)) {
61 throw std::runtime_error(
"failed to close raw binary file");
63 my_file.handle =
nullptr;
67 SelfClosingFILE my_file;
Write bytes to a file.
Definition RawFileWriter.hpp:39
void finish()
Definition RawFileWriter.hpp:59
RawFileWriter(const char *path, const RawFileWriterOptions &options)
Definition RawFileWriter.hpp:45
void write(const unsigned char *buffer, std::size_t n)
Definition RawFileWriter.hpp:52
Virtual class for writing bytes to a sink.
Definition Writer.hpp:21
virtual void write(const unsigned char *buffer, std::size_t n)=0
Simple byte readers and writers.
Options for the RawFileWriter constructor.
Definition RawFileWriter.hpp:24
std::optional< std::size_t > bufsiz
Definition RawFileWriter.hpp:30