1#ifndef CODEX_BASE64_BLOCK_H
2#define CODEX_BASE64_BLOCK_H
23 std::invoke_result_t<T, std::size_t>,
26inline std::optional<std::size_t>
read_all(
27 FILE *
f, std::size_t size, std::span<char>
s);
30 FILE *in, FILE *out, std::size_t size,
31 std::span<char> in_s, std::span<char> out_s,
44 FILE *
f, std::size_t size, std::span<char>
s
46 assert(
s.
size() % size == 0);
51 std::cerr <<
"fread: " << std::strerror(errno) <<
'\n';
54 }
while(!feof(
f) &&
n !=
s.
size());
55 if(
const auto r =
n % size)
56 std::memset(
s.
data() +
n, 0, size -
r);
64 for(std::size_t
n = 0;
n !=
s.
size();) {
67 std::cerr <<
"fwrite: " << std::strerror(errno) <<
'\n';
81 FILE *in, FILE *out, std::size_t size,
82 std::span<char> in_s, std::span<char> out_s,
86 if(
const auto n =
read_all(in, size, in_s); !
n)
88 else if(
const auto ret =
f(*
n); !ret)
90 else if(!
write_all(out, {out_s.data(), ret}))
#define f(x)
Definition 5.c:2
bool process_blocks(FILE *in, FILE *out, std::size_t size, std::span< char > in_s, std::span< char > out_s, ProcessingFunc auto f)
Reads block of a specific size, processes them, and outputs.
Definition block.hpp:80
bool write_all(FILE *f, std::string_view s)
Writes the entire content of s into an output stream.
Definition block.hpp:63
std::optional< std::size_t > read_all(FILE *f, std::size_t size, std::span< char > s)
Reads a block of a specific size.
Definition block.hpp:43
Processes an input buffer.
Definition block.hpp:21
#define r(x, y)
Definition std2.c:13
constexpr const char * data(void) const
Definition utils.hpp:18
constexpr std::size_t size(void) const
Definition utils.hpp:17
constexpr fixed_string s
Definition test.cpp:6