fs/io/BufferedReader: add ReadFull(size_t)
This commit is contained in:
parent
5f66af3712
commit
8748b2dc3f
@ -53,6 +53,19 @@ BufferedReader::Fill(bool need_more)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
BufferedReader::ReadFull(size_t size)
|
||||||
|
{
|
||||||
|
while (true) {
|
||||||
|
auto r = Read();
|
||||||
|
if (r.size >= size)
|
||||||
|
return r.data;
|
||||||
|
|
||||||
|
if (!Fill(true))
|
||||||
|
throw std::runtime_error("Premature end of file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
BufferedReader::ReadFromBuffer(WritableBuffer<void> dest)
|
BufferedReader::ReadFromBuffer(WritableBuffer<void> dest)
|
||||||
{
|
{
|
||||||
|
@ -51,6 +51,14 @@ public:
|
|||||||
return buffer.Read().ToVoid();
|
return buffer.Read().ToVoid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read a buffer of exactly the given size (without consuming
|
||||||
|
* it). Throws std::runtime_error if not enough data is
|
||||||
|
* available.
|
||||||
|
*/
|
||||||
|
gcc_pure
|
||||||
|
void *ReadFull(size_t size);
|
||||||
|
|
||||||
void Consume(size_t n) {
|
void Consume(size_t n) {
|
||||||
buffer.Consume(n);
|
buffer.Consume(n);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user