summaryrefslogtreecommitdiffstats
path: root/hostTools/lzma/compress/InByte.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'hostTools/lzma/compress/InByte.cpp')
-rw-r--r--hostTools/lzma/compress/InByte.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/hostTools/lzma/compress/InByte.cpp b/hostTools/lzma/compress/InByte.cpp
new file mode 100644
index 0000000..03f6a62
--- /dev/null
+++ b/hostTools/lzma/compress/InByte.cpp
@@ -0,0 +1,41 @@
+#include "InByte.h"
+
+namespace NStream{
+
+CInByte::CInByte(UINT32 aBufferSize):
+ m_BufferSize(aBufferSize),
+ m_BufferBase(0)
+{
+ m_BufferBase = new BYTE[m_BufferSize];
+}
+
+CInByte::~CInByte()
+{
+ delete []m_BufferBase;
+}
+
+void CInByte::Init(ISequentialInStream *aStream)
+{
+ m_Stream = aStream;
+ m_ProcessedSize = 0;
+ m_Buffer = m_BufferBase;
+ m_BufferLimit = m_Buffer;
+ m_StreamWasExhausted = false;
+}
+
+bool CInByte::ReadBlock()
+{
+ if (m_StreamWasExhausted)
+ return false;
+ m_ProcessedSize += (m_Buffer - m_BufferBase);
+ UINT32 aNumProcessedBytes;
+ HRESULT aResult = m_Stream->Read(m_BufferBase, m_BufferSize, &aNumProcessedBytes);
+ if (aResult != S_OK)
+ throw aResult;
+ m_Buffer = m_BufferBase;
+ m_BufferLimit = m_Buffer + aNumProcessedBytes;
+ m_StreamWasExhausted = (aNumProcessedBytes == 0);
+ return (!m_StreamWasExhausted);
+}
+
+}