OutStreamWithCRC.h 849 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // OutStreamWithCRC.h
  2. #ifndef __OUTSTREAMWITHCRC_H
  3. #define __OUTSTREAMWITHCRC_H
  4. #include "../../../Common/MyCom.h"
  5. #include "../../IStream.h"
  6. extern "C"
  7. {
  8. #include "../../../../C/7zCrc.h"
  9. }
  10. class COutStreamWithCRC:
  11. public ISequentialOutStream,
  12. public CMyUnknownImp
  13. {
  14. CMyComPtr<ISequentialOutStream> _stream;
  15. UInt64 _size;
  16. UInt32 _crc;
  17. bool _calculate;
  18. public:
  19. MY_UNKNOWN_IMP
  20. STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
  21. void SetStream(ISequentialOutStream *stream) { _stream = stream; }
  22. void ReleaseStream() { _stream.Release(); }
  23. void Init(bool calculate = true)
  24. {
  25. _size = 0;
  26. _calculate = calculate;
  27. _crc = CRC_INIT_VAL;
  28. }
  29. void InitCRC() { _crc = CRC_INIT_VAL; }
  30. UInt64 GetSize() const { return _size; }
  31. UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
  32. };
  33. #endif