1 // InStreamWithCRC.cpp
2
3 #include "StdAfx.h"
4
5 #include "InStreamWithCRC.h"
6
Read(void * data,UInt32 size,UInt32 * processedSize)7 STDMETHODIMP CSequentialInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)
8 {
9 UInt32 realProcessedSize;
10 HRESULT result = _stream->Read(data, size, &realProcessedSize);
11 _size += realProcessedSize;
12 if (size > 0 && realProcessedSize == 0)
13 _wasFinished = true;
14 _crc = CrcUpdate(_crc, data, realProcessedSize);
15 if(processedSize != NULL)
16 *processedSize = realProcessedSize;
17 return result;
18 }
19
Read(void * data,UInt32 size,UInt32 * processedSize)20 STDMETHODIMP CInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)
21 {
22 UInt32 realProcessedSize;
23 HRESULT result = _stream->Read(data, size, &realProcessedSize);
24 if (size > 0 && realProcessedSize == 0)
25 _wasFinished = true;
26 _size += realProcessedSize;
27 _crc = CrcUpdate(_crc, data, realProcessedSize);
28 if(processedSize != NULL)
29 *processedSize = realProcessedSize;
30 return result;
31 }
32
Seek(Int64 offset,UInt32 seekOrigin,UInt64 * newPosition)33 STDMETHODIMP CInStreamWithCRC::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
34 {
35 if (seekOrigin != STREAM_SEEK_SET || offset != 0)
36 return E_FAIL;
37 _size = 0;
38 _crc = CRC_INIT_VAL;
39 return _stream->Seek(offset, seekOrigin, newPosition);
40 }
41