Add Source.drainInto(Sink)

This commit is contained in:
Robert Hensing 2020-09-13 14:39:11 +02:00
parent 9ee3122ec7
commit 29c82ccc77
2 changed files with 12 additions and 3 deletions

View file

@ -93,7 +93,7 @@ void Source::operator () (unsigned char * data, size_t len)
}
std::string Source::drain()
void Source::drainInto(Sink & sink)
{
std::string s;
std::vector<unsigned char> buf(8192);
@ -101,12 +101,19 @@ std::string Source::drain()
size_t n;
try {
n = read(buf.data(), buf.size());
s.append((char *) buf.data(), n);
sink(buf.data(), n);
} catch (EndOfFile &) {
break;
}
}
return s;
}
std::string Source::drain()
{
StringSink s;
drainInto(s);
return *s.s;
}

View file

@ -69,6 +69,8 @@ struct Source
virtual bool good() { return true; }
void drainInto(Sink & sink);
std::string drain();
};