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