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