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 realProcessed = 0;
10   HRESULT result = S_OK;
11   if (_stream)
12     result = _stream->Read(data, size, &realProcessed);
13   _size += realProcessed;
14   if (size != 0 && realProcessed == 0)
15     _wasFinished = true;
16   _crc = CrcUpdate(_crc, data, realProcessed);
17   if (processedSize)
18     *processedSize = realProcessed;
19   return result;
20 }
21 
Read(void * data,UInt32 size,UInt32 * processedSize)22 STDMETHODIMP CInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)
23 {
24   UInt32 realProcessed = 0;
25   HRESULT result = S_OK;
26   if (_stream)
27     result = _stream->Read(data, size, &realProcessed);
28   _size += realProcessed;
29   /*
30   if (size != 0 && realProcessed == 0)
31     _wasFinished = true;
32   */
33   _crc = CrcUpdate(_crc, data, realProcessed);
34   if (processedSize)
35     *processedSize = realProcessed;
36   return result;
37 }
38 
Seek(Int64 offset,UInt32 seekOrigin,UInt64 * newPosition)39 STDMETHODIMP CInStreamWithCRC::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
40 {
41   if (seekOrigin != STREAM_SEEK_SET || offset != 0)
42     return E_FAIL;
43   _size = 0;
44   _crc = CRC_INIT_VAL;
45   return _stream->Seek(offset, seekOrigin, newPosition);
46 }
47