1 #ifndef IOUTILITIES_COPY_H
2 #define IOUTILITIES_COPY_H
19 void copy(std::istream &input, std::ostream &output, std::size_t count);
20 void callbackCopy(std::istream &input, std::ostream &output, std::size_t count,
const std::function<
bool(
void)> &isAborted,
21 const std::function<
void(
double)> &callback);
24 const std::function<
void(
double)> &callback);
28 char m_buffer[bufferSize];
45 while (count > bufferSize) {
46 input.read(m_buffer, bufferSize);
47 output.write(m_buffer, bufferSize);
50 input.read(m_buffer,
static_cast<std::streamsize
>(count));
51 output.write(m_buffer,
static_cast<std::streamsize
>(count));
64 template <std::
size_t bufferSize>
66 const std::function<
void(
double)> &callback)
68 const auto totalBytes = count;
69 while (count > bufferSize) {
70 input.read(m_buffer, bufferSize);
71 output.write(m_buffer, bufferSize);
76 callback(
static_cast<double>(totalBytes - count) /
static_cast<double>(totalBytes));
78 input.read(m_buffer,
static_cast<std::streamsize
>(count));
79 output.write(m_buffer,
static_cast<std::streamsize
>(count));
92 copy(
static_cast<std::istream &
>(input),
static_cast<std::ostream &
>(output), count);
106 template <std::
size_t bufferSize>
108 const std::function<
bool(
void)> &isAborted,
const std::function<
void(
double)> &callback)
110 callbackCopy(
static_cast<std::istream &
>(input),
static_cast<std::ostream &
>(output), count, isAborted, callback);
The CopyHelper class helps to copy bytes from one stream to another.
char * buffer()
Returns the internal buffer.
void copy(std::istream &input, std::ostream &output, std::size_t count)
Copies count bytes from input to output.
CopyHelper()
Constructs a new copy helper.
void callbackCopy(std::istream &input, std::ostream &output, std::size_t count, const std::function< bool(void)> &isAborted, const std::function< void(double)> &callback)
Copies count bytes from input to output.
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.
Contains all utilities provides by the c++utilities library.
std::fstream NativeFileStream