1 | /* |
2 | Copyright (C) 2005-2006 NSRT Team ( http://nsrt.edgeemu.com ) |
3 | Copyright (C) 2002 Andrea Mazzoleni ( http://advancemame.sf.net ) |
4 | Copyright (C) 2001-4 Igor Pavlov ( http://www.7-zip.org ) |
5 | |
6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Lesser General Public |
8 | License version 2.1 as published by the Free Software Foundation. |
9 | |
10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Lesser General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with this library; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | */ |
19 | |
20 | #include "inbyte.h" |
21 | |
22 | namespace NStream{ |
23 | |
24 | CInByte::CInByte(UINT32 aBufferSize): |
25 | m_BufferBase(0), |
26 | m_BufferSize(aBufferSize) |
27 | { |
28 | m_BufferBase = new BYTE[m_BufferSize]; |
29 | } |
30 | |
31 | CInByte::~CInByte() |
32 | { |
33 | delete []m_BufferBase; |
34 | } |
35 | |
36 | void 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 | |
45 | bool 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 | |