
#include "ArchiveStream.h"

#include "Archive.h"

ArchiveStream::ArchiveStream(ArchiveFile* const f)
{
	m_File = f;
}

ArchiveStream::~ArchiveStream(void)
{
}

void ArchiveStream::Write(const int i)
{
	m_File->Write(&i, sizeof(int));
}

void ArchiveStream::Write(const XString& str)
{
	int l = str.getlen();
	m_File->Write(&l, sizeof(int));
	if(l > 0)
		m_File->Write(str.getbuffer(), sizeof(char) * l);
}

XString ArchiveStream::ReadString(void)
{
	XString str;
	
	int l = ReadInt();

	if (l > 0)
	{
		str.SetLength(l);
		m_File->Read(str.getbuffer(), sizeof(char) * l);
	}

	return str;
}

int ArchiveStream::ReadInt(void)
{
	int i = 0;
	m_File->Read(&i, sizeof(int));
	return i;
}