diff src/win32/7zip/7z/CPP/7zip/Archive/Common/InStreamWithCRC.h @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Common/InStreamWithCRC.h	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,69 @@
     1.4 +// InStreamWithCRC.h
     1.5 +
     1.6 +#ifndef __INSTREAMWITHCRC_H
     1.7 +#define __INSTREAMWITHCRC_H
     1.8 +
     1.9 +#include "../../../Common/MyCom.h"
    1.10 +#include "../../IStream.h"
    1.11 +
    1.12 +extern "C"
    1.13 +{
    1.14 +#include "../../../../C/7zCrc.h"
    1.15 +}
    1.16 +
    1.17 +class CSequentialInStreamWithCRC:
    1.18 +  public ISequentialInStream,
    1.19 +  public CMyUnknownImp
    1.20 +{
    1.21 +public:
    1.22 +  MY_UNKNOWN_IMP
    1.23 +
    1.24 +  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
    1.25 +private:
    1.26 +  CMyComPtr<ISequentialInStream> _stream;
    1.27 +  UInt64 _size;
    1.28 +  UInt32 _crc;
    1.29 +  bool _wasFinished;
    1.30 +public:
    1.31 +  void SetStream(ISequentialInStream *stream) { _stream = stream;  }
    1.32 +  void Init()
    1.33 +  {
    1.34 +    _size = 0;
    1.35 +    _wasFinished = false;
    1.36 +    _crc = CRC_INIT_VAL;
    1.37 +  }
    1.38 +  void ReleaseStream() { _stream.Release(); }
    1.39 +  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
    1.40 +  UInt64 GetSize() const { return _size; }
    1.41 +  bool WasFinished() const { return _wasFinished; }
    1.42 +};
    1.43 +
    1.44 +class CInStreamWithCRC:
    1.45 +  public IInStream,
    1.46 +  public CMyUnknownImp
    1.47 +{
    1.48 +public:
    1.49 +  MY_UNKNOWN_IMP1(IInStream)
    1.50 +
    1.51 +  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
    1.52 +  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
    1.53 +private:
    1.54 +  CMyComPtr<IInStream> _stream;
    1.55 +  UInt64 _size;
    1.56 +  UInt32 _crc;
    1.57 +  bool _wasFinished;
    1.58 +public:
    1.59 +  void SetStream(IInStream *stream) { _stream = stream;  }
    1.60 +  void Init()
    1.61 +  {
    1.62 +    _size = 0;
    1.63 +    _wasFinished = false;
    1.64 +    _crc = CRC_INIT_VAL;
    1.65 +  }
    1.66 +  void ReleaseStream() { _stream.Release(); }
    1.67 +  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
    1.68 +  UInt64 GetSize() const { return _size; }
    1.69 +  bool WasFinished() const { return _wasFinished; }
    1.70 +};
    1.71 +
    1.72 +#endif