forked from organicmaps/organicmaps
Add Read:reader -> Write:writer function.
This commit is contained in:
parent
e5ee4a4407
commit
d84d08fc22
2 changed files with 23 additions and 1 deletions
|
@ -114,4 +114,21 @@ namespace rw
|
|||
if (count > 0)
|
||||
sink.Write(&v[0], count * sizeof(ValueT));
|
||||
}
|
||||
|
||||
template <class ReaderT, class WriterT>
|
||||
void ReadAndWrite(ReaderT & reader, WriterT & writer, size_t bufferSize = 4*1024)
|
||||
{
|
||||
uint64_t size = reader.Size();
|
||||
vector<char> buffer(min(bufferSize, static_cast<size_t>(size)));
|
||||
|
||||
while (size > 0)
|
||||
{
|
||||
size_t const curr = min(bufferSize, static_cast<size_t>(size));
|
||||
|
||||
reader.Read(&buffer[0], curr);
|
||||
writer.Write(&buffer[0], curr);
|
||||
|
||||
size -= curr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,7 +182,7 @@ public:
|
|||
{
|
||||
if (m_pos + size > m_reader.Size())
|
||||
{
|
||||
size_t remainingSize = static_cast<size_t>(m_reader.Size() - m_pos);
|
||||
size_t const remainingSize = static_cast<size_t>(Size());
|
||||
m_reader.Read(m_pos, p, remainingSize);
|
||||
m_pos = m_reader.Size();
|
||||
MYTHROW1(SourceOutOfBoundsException, remainingSize, ());
|
||||
|
@ -204,6 +204,11 @@ public:
|
|||
return m_pos;
|
||||
}
|
||||
|
||||
uint64_t Size() const
|
||||
{
|
||||
return (m_reader.Size() - m_pos);
|
||||
}
|
||||
|
||||
ReaderT const & Reader() const
|
||||
{
|
||||
return m_reader;
|
||||
|
|
Loading…
Add table
Reference in a new issue