1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include "OutByte.h"
namespace NStream {
COutByte::COutByte(INT aBufferSize):
m_BufferSize(aBufferSize)
{
m_Buffer = new BYTE[m_BufferSize];
}
COutByte::~COutByte()
{
delete []m_Buffer;
}
void COutByte::Init(ISequentialOutStream *aStream)
{
m_Stream = aStream;
m_ProcessedSize = 0;
m_Pos = 0;
}
HRESULT COutByte::Flush()
{
if (m_Pos == 0)
return S_OK;
INT aProcessedSize;
HRESULT aResult = m_Stream->Write(m_Buffer, m_Pos, &aProcessedSize);
if (aResult != S_OK)
return aResult;
if (m_Pos != aProcessedSize)
return E_FAIL;
m_ProcessedSize += aProcessedSize;
m_Pos = 0;
return S_OK;
}
void COutByte::WriteBlock()
{
HRESULT aResult = Flush();
if (aResult != S_OK)
throw aResult;
}
}
|