io: add iterative file reading helper
This commit is contained in:
parent
c64cd2eb29
commit
ad916e61c9
18
io.hpp
18
io.hpp
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user