misc/libphysfs/lzma/CPP/7zip/Common/StreamObjects.cpp
changeset 12213 bb5522e88ab2
equal deleted inserted replaced
12212:ea891871f481 12213:bb5522e88ab2
       
     1 // StreamObjects.cpp
       
     2 
       
     3 #include "StdAfx.h"
       
     4 
       
     5 #include "StreamObjects.h"
       
     6 #include "../../Common/Defs.h"
       
     7 
       
     8 
       
     9 STDMETHODIMP CSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)
       
    10 {
       
    11   UInt32 numBytesToRead = (UInt32)(MyMin(_pos + size, _size) - _pos);
       
    12   memmove(data, _dataPointer + _pos, numBytesToRead);
       
    13   _pos += numBytesToRead;
       
    14   if(processedSize != NULL)
       
    15     *processedSize = numBytesToRead;
       
    16   return S_OK;
       
    17 }
       
    18 
       
    19 
       
    20 void CWriteBuffer::Write(const void *data, size_t size)
       
    21 {
       
    22   size_t newCapacity = _size + size;
       
    23   _buffer.EnsureCapacity(newCapacity);
       
    24   memmove(_buffer + _size, data, size);
       
    25   _size += size;
       
    26 }
       
    27 
       
    28 STDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UInt32 size, UInt32 *processedSize)
       
    29 {
       
    30   _writeBuffer.Write(data, size);
       
    31   if(processedSize != NULL)
       
    32     *processedSize = size;
       
    33   return S_OK; 
       
    34 }
       
    35 
       
    36 STDMETHODIMP CSequentialOutStreamImp2::Write(const void *data, UInt32 size, UInt32 *processedSize)
       
    37 {
       
    38   UInt32 newSize = size;
       
    39   if (_pos + size > _size)
       
    40     newSize = (UInt32)(_size - _pos);
       
    41   memmove(_buffer + _pos, data, newSize);
       
    42   if(processedSize != NULL)
       
    43     *processedSize = newSize;
       
    44   _pos += newSize;
       
    45   if (newSize != size)
       
    46     return E_FAIL;
       
    47   return S_OK; 
       
    48 }
       
    49 
       
    50 STDMETHODIMP CSequentialInStreamSizeCount::Read(void *data, UInt32 size, UInt32 *processedSize)
       
    51 {
       
    52   UInt32 realProcessedSize;
       
    53   HRESULT result = _stream->Read(data, size, &realProcessedSize);
       
    54   _size += realProcessedSize;
       
    55   if (processedSize != 0)
       
    56     *processedSize = realProcessedSize;
       
    57   return result; 
       
    58 }
       
    59 
       
    60 STDMETHODIMP CSequentialOutStreamSizeCount::Write(const void *data, UInt32 size, UInt32 *processedSize)
       
    61 {
       
    62   UInt32 realProcessedSize;
       
    63   HRESULT result = _stream->Write(data, size, &realProcessedSize);
       
    64   _size += realProcessedSize;
       
    65   if (processedSize != 0)
       
    66     *processedSize = realProcessedSize;
       
    67   return result; 
       
    68 }