1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00
vcmi/lib/Filesystem/CMemoryStream.cpp

49 lines
756 B
C++
Raw Normal View History

#include "StdInc.h"
#include "CMemoryStream.h"
CMemoryStream::CMemoryStream(const ui8 * data, si64 size, bool freeData /*= false*/):
data(data),
size(size),
position(0),
freeData(freeData)
{
}
CMemoryStream::~CMemoryStream()
{
if(freeData)
{
delete[] data;
}
}
si64 CMemoryStream::read(ui8 * data, si64 size)
{
std::copy(this->data + position, this->data + position + size, data);
position += size;
return size;
}
si64 CMemoryStream::seek(si64 position)
{
si64 diff = this->position;
this->position = position;
return position - diff;
}
si64 CMemoryStream::tell()
{
return this->position;
}
si64 CMemoryStream::skip(si64 delta)
{
this->position += delta;
return delta;
}
si64 CMemoryStream::getSize()
{
return size;
}