misc/libphysfs/lzma/CPP/7zip/Archive/Common/InStreamWithCRC.cpp
branchui-scaling
changeset 15283 c4fd2813b127
parent 13390 0135e64c6c66
parent 15279 7ab5cf405686
child 15663 d92eeb468dad
equal deleted inserted replaced
13390:0135e64c6c66 15283:c4fd2813b127
     1 // InStreamWithCRC.cpp
       
     2 
       
     3 #include "StdAfx.h"
       
     4 
       
     5 #include "InStreamWithCRC.h"
       
     6 
       
     7 STDMETHODIMP CSequentialInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)
       
     8 {
       
     9   UInt32 realProcessedSize;
       
    10   HRESULT result = _stream->Read(data, size, &realProcessedSize);
       
    11   _size += realProcessedSize;
       
    12   if (size > 0 && realProcessedSize == 0)
       
    13     _wasFinished = true;
       
    14   _crc = CrcUpdate(_crc, data, realProcessedSize);
       
    15   if(processedSize != NULL)
       
    16     *processedSize = realProcessedSize;
       
    17   return result;
       
    18 }
       
    19 
       
    20 STDMETHODIMP CInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)
       
    21 {
       
    22   UInt32 realProcessedSize;
       
    23   HRESULT result = _stream->Read(data, size, &realProcessedSize);
       
    24   if (size > 0 && realProcessedSize == 0)
       
    25     _wasFinished = true;
       
    26   _size += realProcessedSize;
       
    27   _crc = CrcUpdate(_crc, data, realProcessedSize);
       
    28   if(processedSize != NULL)
       
    29     *processedSize = realProcessedSize;
       
    30   return result;
       
    31 }
       
    32 
       
    33 STDMETHODIMP CInStreamWithCRC::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
       
    34 {
       
    35   if (seekOrigin != STREAM_SEEK_SET || offset != 0)
       
    36     return E_FAIL;
       
    37   _size = 0;
       
    38   _crc = CRC_INIT_VAL;
       
    39   return _stream->Seek(offset, seekOrigin, newPosition);
       
    40 }