Mercurial > vba-linux
diff src/win32/7zip/7z/CPP/7zip/Compress/CopyCoder.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/Compress/CopyCoder.cpp Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,62 @@ 1.4 +// Compress/CopyCoder.cpp 1.5 + 1.6 +#include "StdAfx.h" 1.7 + 1.8 +extern "C" 1.9 +{ 1.10 +#include "../../../C/Alloc.h" 1.11 +} 1.12 + 1.13 +#include "../Common/StreamUtils.h" 1.14 + 1.15 +#include "CopyCoder.h" 1.16 + 1.17 +namespace NCompress { 1.18 + 1.19 +static const UInt32 kBufferSize = 1 << 17; 1.20 + 1.21 +CCopyCoder::~CCopyCoder() 1.22 +{ 1.23 + ::MidFree(_buffer); 1.24 +} 1.25 + 1.26 +STDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream, 1.27 + ISequentialOutStream *outStream, 1.28 + const UInt64 * /* inSize */, const UInt64 *outSize, 1.29 + ICompressProgressInfo *progress) 1.30 +{ 1.31 + if (_buffer == 0) 1.32 + { 1.33 + _buffer = (Byte *)::MidAlloc(kBufferSize); 1.34 + if (_buffer == 0) 1.35 + return E_OUTOFMEMORY; 1.36 + } 1.37 + 1.38 + TotalSize = 0; 1.39 + for (;;) 1.40 + { 1.41 + UInt32 realProcessedSize; 1.42 + UInt32 size = kBufferSize; 1.43 + if (outSize != 0) 1.44 + if (size > *outSize - TotalSize) 1.45 + size = (UInt32)(*outSize - TotalSize); 1.46 + RINOK(inStream->Read(_buffer, size, &realProcessedSize)); 1.47 + if (realProcessedSize == 0) 1.48 + break; 1.49 + RINOK(WriteStream(outStream, _buffer, realProcessedSize)); 1.50 + TotalSize += realProcessedSize; 1.51 + if (progress != NULL) 1.52 + { 1.53 + RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize)); 1.54 + } 1.55 + } 1.56 + return S_OK; 1.57 +} 1.58 + 1.59 +STDMETHODIMP CCopyCoder::GetInStreamProcessedSize(UInt64 *value) 1.60 +{ 1.61 + *value = TotalSize; 1.62 + return S_OK; 1.63 +} 1.64 + 1.65 +}