• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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);
SetStream(ISequentialOutStream * stream)23   void SetStream(ISequentialOutStream *stream) { _stream = stream; }
ReleaseStream()24   void ReleaseStream() { _stream.Release(); }
25   void Init(bool calculate = true)
26   {
27     _size = 0;
28     _calculate = calculate;
29     _crc = CRC_INIT_VAL;
30   }
EnableCalc(bool calculate)31   void EnableCalc(bool calculate) { _calculate = calculate; }
InitCRC()32   void InitCRC() { _crc = CRC_INIT_VAL; }
GetSize()33   UInt64 GetSize() const { return _size; }
GetCRC()34   UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
35 };
36 
37 #endif
38