summaryrefslogtreecommitdiffstats
path: root/hostTools/lzma/compress/OutByte.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'hostTools/lzma/compress/OutByte.cpp')
-rw-r--r--hostTools/lzma/compress/OutByte.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/hostTools/lzma/compress/OutByte.cpp b/hostTools/lzma/compress/OutByte.cpp
new file mode 100644
index 0000000..a658798
--- /dev/null
+++ b/hostTools/lzma/compress/OutByte.cpp
@@ -0,0 +1,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;
+}
+
+}