misc/libphysfs/lzma/CPP/7zip/Archive/Common/InStreamWithCRC.h
changeset 13881 99b265e0d1d0
parent 13880 5f819b90d479
child 13882 b172a5d40eee
equal deleted inserted replaced
13880:5f819b90d479 13881:99b265e0d1d0
     1 // InStreamWithCRC.h
       
     2 
       
     3 #ifndef __INSTREAMWITHCRC_H
       
     4 #define __INSTREAMWITHCRC_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 CSequentialInStreamWithCRC: 
       
    15   public ISequentialInStream,
       
    16   public CMyUnknownImp
       
    17 {
       
    18 public:
       
    19   MY_UNKNOWN_IMP
       
    20 
       
    21   STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
       
    22 private:
       
    23   CMyComPtr<ISequentialInStream> _stream;
       
    24   UInt64 _size;
       
    25   UInt32 _crc;
       
    26   bool _wasFinished;
       
    27 public:
       
    28   void SetStream(ISequentialInStream *stream) { _stream = stream;  }
       
    29   void Init()
       
    30   {
       
    31     _size = 0;
       
    32     _wasFinished = false;
       
    33     _crc = CRC_INIT_VAL;
       
    34   }
       
    35   void ReleaseStream() { _stream.Release(); }
       
    36   UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
       
    37   UInt64 GetSize() const { return _size; }
       
    38   bool WasFinished() const { return _wasFinished; }
       
    39 };
       
    40 
       
    41 class CInStreamWithCRC: 
       
    42   public IInStream,
       
    43   public CMyUnknownImp
       
    44 {
       
    45 public:
       
    46   MY_UNKNOWN_IMP1(IInStream)
       
    47 
       
    48   STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
       
    49   STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
       
    50 private:
       
    51   CMyComPtr<IInStream> _stream;
       
    52   UInt64 _size;
       
    53   UInt32 _crc;
       
    54   bool _wasFinished;
       
    55 public:
       
    56   void SetStream(IInStream *stream) { _stream = stream;  }
       
    57   void Init()
       
    58   {
       
    59     _size = 0;
       
    60     _wasFinished = false;
       
    61     _crc = CRC_INIT_VAL;
       
    62   }
       
    63   void ReleaseStream() { _stream.Release(); }
       
    64   UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
       
    65   UInt64 GetSize() const { return _size; }
       
    66   bool WasFinished() const { return _wasFinished; }
       
    67 };
       
    68 
       
    69 #endif