diff src/win32/7zip/7z/CPP/7zip/Common/StreamObjects.cpp @ 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/Common/StreamObjects.cpp	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,68 @@
     1.4 +// StreamObjects.cpp
     1.5 +
     1.6 +#include "StdAfx.h"
     1.7 +
     1.8 +#include "StreamObjects.h"
     1.9 +#include "../../Common/Defs.h"
    1.10 +
    1.11 +
    1.12 +STDMETHODIMP CSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)
    1.13 +{
    1.14 +  size_t rem = _size - _pos;
    1.15 +  if (size < rem)
    1.16 +    rem = (size_t)size;
    1.17 +  memcpy(data, _dataPointer + _pos, rem);
    1.18 +  _pos += rem;
    1.19 +  if (processedSize != NULL)
    1.20 +    *processedSize = (UInt32)rem;
    1.21 +  return S_OK;
    1.22 +}
    1.23 +
    1.24 +
    1.25 +void CWriteBuffer::Write(const void *data, size_t size)
    1.26 +{
    1.27 +  size_t newCapacity = _size + size;
    1.28 +  _buffer.EnsureCapacity(newCapacity);
    1.29 +  memcpy(_buffer + _size, data, size);
    1.30 +  _size += size;
    1.31 +}
    1.32 +
    1.33 +STDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UInt32 size, UInt32 *processedSize)
    1.34 +{
    1.35 +  _writeBuffer.Write(data, (size_t)size);
    1.36 +  if(processedSize != NULL)
    1.37 +    *processedSize = size;
    1.38 +  return S_OK;
    1.39 +}
    1.40 +
    1.41 +STDMETHODIMP CSequentialOutStreamImp2::Write(const void *data, UInt32 size, UInt32 *processedSize)
    1.42 +{
    1.43 +  size_t rem = _size - _pos;
    1.44 +  if (size < rem)
    1.45 +    rem = (size_t)size;
    1.46 +  memcpy(_buffer + _pos, data, rem);
    1.47 +  _pos += rem;
    1.48 +  if (processedSize != NULL)
    1.49 +    *processedSize = (UInt32)rem;
    1.50 +  return (rem == size ? S_OK : E_FAIL);
    1.51 +}
    1.52 +
    1.53 +STDMETHODIMP CSequentialInStreamSizeCount::Read(void *data, UInt32 size, UInt32 *processedSize)
    1.54 +{
    1.55 +  UInt32 realProcessedSize;
    1.56 +  HRESULT result = _stream->Read(data, size, &realProcessedSize);
    1.57 +  _size += realProcessedSize;
    1.58 +  if (processedSize != 0)
    1.59 +    *processedSize = realProcessedSize;
    1.60 +  return result;
    1.61 +}
    1.62 +
    1.63 +STDMETHODIMP CSequentialOutStreamSizeCount::Write(const void *data, UInt32 size, UInt32 *processedSize)
    1.64 +{
    1.65 +  UInt32 realProcessedSize;
    1.66 +  HRESULT result = _stream->Write(data, size, &realProcessedSize);
    1.67 +  _size += realProcessedSize;
    1.68 +  if (processedSize != 0)
    1.69 +    *processedSize = realProcessedSize;
    1.70 +  return result;
    1.71 +}