1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-28 23:06:24 +02:00
vcmi/lib/filesystem/CMemoryStream.cpp
2013-04-07 10:48:07 +00:00

41 lines
746 B
C++

#include "StdInc.h"
#include "CMemoryStream.h"
CMemoryStream::CMemoryStream(const ui8 * data, si64 size) :
data(data), size(size), position(0)
{
}
si64 CMemoryStream::read(ui8 * data, si64 size)
{
si64 toRead = std::min(this->size - tell(), size);
std::copy(this->data + position, this->data + position + toRead, data);
position += size;
return toRead;
}
si64 CMemoryStream::seek(si64 position)
{
si64 origin = tell();
this->position = std::min(position, size);
return tell() - origin;
}
si64 CMemoryStream::tell()
{
return this->position;
}
si64 CMemoryStream::skip(si64 delta)
{
si64 origin = tell();
this->position += std::min(size - origin, delta);
return tell() - origin;
}
si64 CMemoryStream::getSize()
{
return size;
}