1/*
2Copyright (C) 2005-2006 NSRT Team ( http://nsrt.edgeemu.com )
3Copyright (C) 2002 Andrea Mazzoleni ( http://advancemame.sf.net )
4Copyright (C) 2001-4 Igor Pavlov ( http://www.7-zip.org )
5
6This library is free software; you can redistribute it and/or
7modify it under the terms of the GNU Lesser General Public
8License version 2.1 as published by the Free Software Foundation.
9
10This library is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public
16License along with this library; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19
20#include "inbyte.h"
21
22namespace NStream{
23
24CInByte::CInByte(UINT32 aBufferSize):
25 m_BufferBase(0),
26 m_BufferSize(aBufferSize)
27{
28 m_BufferBase = new BYTE[m_BufferSize];
29}
30
31CInByte::~CInByte()
32{
33 delete []m_BufferBase;
34}
35
36void CInByte::Init(ISequentialInStream *aStream)
37{
38 m_Stream = aStream;
39 m_ProcessedSize = 0;
40 m_Buffer = m_BufferBase;
41 m_BufferLimit = m_Buffer;
42 m_StreamWasExhausted = false;
43}
44
45bool CInByte::ReadBlock()
46{
47 if (m_StreamWasExhausted)
48 return false;
49 m_ProcessedSize += (m_Buffer - m_BufferBase);
50 UINT32 aNumProcessedBytes;
51 HRESULT aResult = m_Stream->Read(m_BufferBase, m_BufferSize, &aNumProcessedBytes);
52 if (aResult != S_OK)
53 throw aResult;
54 m_Buffer = m_BufferBase;
55 m_BufferLimit = m_Buffer + aNumProcessedBytes;
56 m_StreamWasExhausted = (aNumProcessedBytes == 0);
57 return (!m_StreamWasExhausted);
58}
59
60}
61