1 // InStreamWithCRC.cpp
2
3 #include "StdAfx.h"
4
5 #include "InStreamWithCRC.h"
6
Z7_COM7F_IMF(CSequentialInStreamWithCRC::Read (void * data,UInt32 size,UInt32 * processedSize))7 Z7_COM7F_IMF(CSequentialInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize))
8 {
9 UInt32 realProcessed = 0;
10 HRESULT result = S_OK;
11 if (size != 0)
12 {
13 if (_stream)
14 result = _stream->Read(data, size, &realProcessed);
15 _size += realProcessed;
16 if (realProcessed == 0)
17 _wasFinished = true;
18 else
19 _crc = CrcUpdate(_crc, data, realProcessed);
20 }
21 if (processedSize)
22 *processedSize = realProcessed;
23 return result;
24 }
25
Z7_COM7F_IMF(CSequentialInStreamWithCRC::GetSize (UInt64 * size))26 Z7_COM7F_IMF(CSequentialInStreamWithCRC::GetSize(UInt64 *size))
27 {
28 *size = _fullSize;
29 return S_OK;
30 }
31
32
Z7_COM7F_IMF(CInStreamWithCRC::Read (void * data,UInt32 size,UInt32 * processedSize))33 Z7_COM7F_IMF(CInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize))
34 {
35 UInt32 realProcessed = 0;
36 HRESULT result = S_OK;
37 if (_stream)
38 result = _stream->Read(data, size, &realProcessed);
39 _size += realProcessed;
40 /*
41 if (size != 0 && realProcessed == 0)
42 _wasFinished = true;
43 */
44 _crc = CrcUpdate(_crc, data, realProcessed);
45 if (processedSize)
46 *processedSize = realProcessed;
47 return result;
48 }
49
Z7_COM7F_IMF(CInStreamWithCRC::Seek (Int64 offset,UInt32 seekOrigin,UInt64 * newPosition))50 Z7_COM7F_IMF(CInStreamWithCRC::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition))
51 {
52 if (seekOrigin != STREAM_SEEK_SET || offset != 0)
53 return E_FAIL;
54 _size = 0;
55 _crc = CRC_INIT_VAL;
56 return _stream->Seek(offset, seekOrigin, newPosition);
57 }
58