tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

OutStreamWithCRC.h (937B)


      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 EnableCalc(bool calculate) { _calculate = calculate; }
     32  void InitCRC() { _crc = CRC_INIT_VAL; }
     33  UInt64 GetSize() const { return _size; }
     34  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
     35 };
     36 
     37 #endif