1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/other-licenses/7zstub/src/7zip/Compress/Copy/CopyCoder.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,52 @@ 1.4 +// Compress/CopyCoder.cpp 1.5 + 1.6 +#include "StdAfx.h" 1.7 + 1.8 +#include "CopyCoder.h" 1.9 +#include "../../../Common/Alloc.h" 1.10 +#include "../../Common/StreamUtils.h" 1.11 + 1.12 +namespace NCompress { 1.13 + 1.14 +static const UInt32 kBufferSize = 1 << 17; 1.15 + 1.16 +CCopyCoder::~CCopyCoder() 1.17 +{ 1.18 + ::MidFree(_buffer); 1.19 +} 1.20 + 1.21 +STDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream, 1.22 + ISequentialOutStream *outStream, 1.23 + const UInt64 *inSize, const UInt64 *outSize, 1.24 + ICompressProgressInfo *progress) 1.25 +{ 1.26 + if (_buffer == 0) 1.27 + { 1.28 + _buffer = (Byte *)::MidAlloc(kBufferSize); 1.29 + if (_buffer == 0) 1.30 + return E_OUTOFMEMORY; 1.31 + } 1.32 + 1.33 + TotalSize = 0; 1.34 + while(true) 1.35 + { 1.36 + UInt32 realProcessedSize; 1.37 + UInt32 size = kBufferSize; 1.38 + if (outSize != 0) 1.39 + if (size > *outSize - TotalSize) 1.40 + size = (UInt32)(*outSize - TotalSize); 1.41 + RINOK(inStream->Read(_buffer, size, &realProcessedSize)); 1.42 + if(realProcessedSize == 0) 1.43 + break; 1.44 + RINOK(WriteStream(outStream, _buffer, realProcessedSize, NULL)); 1.45 + TotalSize += realProcessedSize; 1.46 + if (progress != NULL) 1.47 + { 1.48 + RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize)); 1.49 + } 1.50 + } 1.51 + return S_OK; 1.52 +} 1.53 + 1.54 +} 1.55 +