forked from lix-project/lix
Add Source.drainInto(Sink)
This commit is contained in:
parent
9ee3122ec7
commit
29c82ccc77
|
@ -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::string s;
|
||||||
std::vector<unsigned char> buf(8192);
|
std::vector<unsigned char> buf(8192);
|
||||||
|
@ -101,12 +101,19 @@ std::string Source::drain()
|
||||||
size_t n;
|
size_t n;
|
||||||
try {
|
try {
|
||||||
n = read(buf.data(), buf.size());
|
n = read(buf.data(), buf.size());
|
||||||
s.append((char *) buf.data(), n);
|
sink(buf.data(), n);
|
||||||
} catch (EndOfFile &) {
|
} catch (EndOfFile &) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s;
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string Source::drain()
|
||||||
|
{
|
||||||
|
StringSink s;
|
||||||
|
drainInto(s);
|
||||||
|
return *s.s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,8 @@ struct Source
|
||||||
|
|
||||||
virtual bool good() { return true; }
|
virtual bool good() { return true; }
|
||||||
|
|
||||||
|
void drainInto(Sink & sink);
|
||||||
|
|
||||||
std::string drain();
|
std::string drain();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue