73 size_t haveRead = 0, haveWritten = 0;
76 while (!stream.
eos() && (n > 0)) {
77 const size_t toRead = MIN<size_t>(4096, n);
78 const size_t bufRead = stream.
read(buf, toRead);
80 const size_t bufWrite =
write(buf, bufRead);
84 haveWritten += bufWrite;
111 offset =
size + offset;
114 return begin + offset;
122 throw Exception(
"Invalid whence (%d)", (
int) whence);
Generic interface for a readable data stream.
virtual void flush()
Commit any buffered data to the underlying channel or storage medium; unbuffered streams can use the ...
A class holding an UTF-8 string.
void writeString(const UString &str)
Write the given string to the stream, encoded as UTF-8.
static size_t evalSeek(ptrdiff_t offset, Origin whence, size_t pos, size_t begin, size_t size)
Evaluate the seek offset relative to whence into a position from the beginning.
virtual bool eos() const =0
Returns true if a read failed because the stream has been reached.
Seek from the current position of the stream.
virtual size_t pos() const =0
Obtains the current value of the stream position indicator of the stream.
const char * c_str() const
Return the (utf8 encoded) string data.
Utility templates and functions.
Basic writing stream interfaces.
virtual size_t read(void *dataPtr, size_t dataSize)=0
Read data from the stream.
const Exception kWriteError("Write error")
Exception when writing to a stream failed.
Seek from the end of the stream.
virtual size_t write(const void *dataPtr, size_t dataSize)=0
Write data into the stream.
Basic reading stream interfaces.
#define XOREOS_FALLTHROUGH
size_t writeStream(ReadStream &stream, size_t n)
Copy n bytes of the given stream into the stream.
Origin
The position a seeking offset takes as a base.
virtual size_t size() const =0
Obtains the total size of the stream, measured in bytes.
Seek from the begin of the stream.