blob: a658798e8ea6f85e84a4ababbfe5c618efc4098b (
plain)
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(UINT32 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;
UINT32 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;
}
}
|