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