32 #ifndef _QORE_TRANSFORMINPUTSTREAM_H
33 #define _QORE_TRANSFORMINPUTSTREAM_H
36 #include "qore/InputStream.h"
37 #include "qore/Transform.h"
44 inBufSize(t->inputBufferSize()),
45 outBufSize(t->outputBufferSize()),
46 buf(new char[inBufSize]),
47 outBuf(new char[outBufSize]) {
50 DLLLOCAL ~TransformInputStream() {
55 DLLLOCAL
const char *
getName()
override {
56 return "TransformInputStream";
60 if (outBufCount > 0) {
61 return readFromBuffer(ptr, limit);
64 if (!eof && inBufSize - bufCount > 0) {
65 int64 r = is->read(buf + bufCount, inBufSize - bufCount, xsink);
76 assert(eof || bufCount > 0);
79 std::pair<int64, int64> r = t->apply(bufCount ? buf :
nullptr, bufCount, outBuf, outBufSize, xsink);
86 memmove(buf, buf + r.first, bufCount);
89 outBufCount = r.second;
90 return readFromBuffer(ptr, limit);
103 return outBuf[outBufOffset];
104 int64 rc =
read(outBuf, outBufSize, xsink);
120 size_t outBufOffset = 0;
124 size_t outBufCount = 0;
127 DLLLOCAL
int64 readFromBuffer(
void *ptr,
int64 limit) {
130 memcpy(ptr, outBuf + outBufOffset, toCopy);
132 outBufCount -= toCopy;
136 outBufOffset += toCopy;
142 #endif // _QORE_TRANSFORMINPUTSTREAM_H