Mercurial > vba-linux
diff src/win32/7zip/7z/CPP/7zip/Common/LimitedStreams.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/LimitedStreams.cpp Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,45 @@ 1.4 +// LimitedStreams.cpp 1.5 + 1.6 +#include "StdAfx.h" 1.7 + 1.8 +#include "LimitedStreams.h" 1.9 +#include "../../Common/Defs.h" 1.10 + 1.11 +STDMETHODIMP CLimitedSequentialInStream::Read(void *data, UInt32 size, UInt32 *processedSize) 1.12 +{ 1.13 + UInt32 realProcessedSize = 0; 1.14 + UInt32 sizeToRead = (UInt32)MyMin((_size - _pos), (UInt64)size); 1.15 + HRESULT result = S_OK; 1.16 + if (sizeToRead > 0) 1.17 + { 1.18 + result = _stream->Read(data, sizeToRead, &realProcessedSize); 1.19 + _pos += realProcessedSize; 1.20 + if (realProcessedSize == 0) 1.21 + _wasFinished = true; 1.22 + } 1.23 + if(processedSize != NULL) 1.24 + *processedSize = realProcessedSize; 1.25 + return result; 1.26 +} 1.27 + 1.28 +STDMETHODIMP CLimitedSequentialOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize) 1.29 +{ 1.30 + HRESULT result = S_OK; 1.31 + if (processedSize != NULL) 1.32 + *processedSize = 0; 1.33 + if (size > _size) 1.34 + { 1.35 + size = (UInt32)_size; 1.36 + if (size == 0) 1.37 + { 1.38 + _overflow = true; 1.39 + return E_FAIL; 1.40 + } 1.41 + } 1.42 + if (_stream) 1.43 + result = _stream->Write(data, size, &size); 1.44 + _size -= size; 1.45 + if (processedSize != NULL) 1.46 + *processedSize = size; 1.47 + return result; 1.48 +}