InStreamWithCRC.h 1.5 KB

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