1// InStreamWithCRC.h
2
3#ifndef __IN_STREAM_WITH_CRC_H
4#define __IN_STREAM_WITH_CRC_H
5
6#include "../../../../C/7zCrc.h"
7
8#include "../../../Common/MyCom.h"
9
10#include "../../IStream.h"
11
12class CSequentialInStreamWithCRC:
13  public ISequentialInStream,
14  public CMyUnknownImp
15{
16public:
17  MY_UNKNOWN_IMP
18
19  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
20private:
21  CMyComPtr<ISequentialInStream> _stream;
22  UInt64 _size;
23  UInt32 _crc;
24  bool _wasFinished;
25public:
26  void SetStream(ISequentialInStream *stream) { _stream = stream;  }
27  void Init()
28  {
29    _size = 0;
30    _wasFinished = false;
31    _crc = CRC_INIT_VAL;
32  }
33  void ReleaseStream() { _stream.Release(); }
34  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
35  UInt64 GetSize() const { return _size; }
36  bool WasFinished() const { return _wasFinished; }
37};
38
39class CInStreamWithCRC:
40  public IInStream,
41  public CMyUnknownImp
42{
43public:
44  MY_UNKNOWN_IMP1(IInStream)
45
46  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
47  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
48private:
49  CMyComPtr<IInStream> _stream;
50  UInt64 _size;
51  UInt32 _crc;
52  // bool _wasFinished;
53public:
54  void SetStream(IInStream *stream) { _stream = stream;  }
55  void Init()
56  {
57    _size = 0;
58    // _wasFinished = false;
59    _crc = CRC_INIT_VAL;
60  }
61  void ReleaseStream() { _stream.Release(); }
62  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
63  UInt64 GetSize() const { return _size; }
64  // bool WasFinished() const { return _wasFinished; }
65};
66
67#endif
68