io: add iterative file reading helper

This commit is contained in:
Danny Robson 2019-06-19 12:00:47 +10:00
parent c64cd2eb29
commit ad916e61c9

18
io.hpp
View File

@ -131,6 +131,24 @@ namespace cruft {
}
///------------------------------------------------------------------------
/// Read the number of bytes covered by the destination view from the
/// source descriptor.
template <typename SrcT>
decltype (auto)
read (SrcT &&src, cruft::view<u08*> dst)
{
auto remain = dst;
while (!remain.empty ()) {
auto const count = src.read (remain.begin (), remain.size () * sizeof (decltype(dst)::value_type));
remain = remain.consume (count);
}
return dst;
}
///////////////////////////////////////////////////////////////////////////
class indenter : public std::streambuf {
protected: