1 // Compress/CopyCoder.cpp
\r
5 #include "../../../C/Alloc.h"
\r
7 #include "../Common/StreamUtils.h"
\r
9 #include "CopyCoder.h"
\r
11 namespace NCompress {
\r
13 static const UInt32 kBufferSize = 1 << 17;
\r
15 CCopyCoder::~CCopyCoder()
\r
20 STDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream,
\r
21 ISequentialOutStream *outStream,
\r
22 const UInt64 * /* inSize */, const UInt64 *outSize,
\r
23 ICompressProgressInfo *progress)
\r
27 _buffer = (Byte *)::MidAlloc(kBufferSize);
\r
29 return E_OUTOFMEMORY;
\r
35 UInt32 size = kBufferSize;
\r
37 if (size > *outSize - TotalSize)
\r
38 size = (UInt32)(*outSize - TotalSize);
\r
39 RINOK(inStream->Read(_buffer, size, &size));
\r
44 RINOK(WriteStream(outStream, _buffer, size));
\r
47 if (progress != NULL)
\r
49 RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize));
\r
55 STDMETHODIMP CCopyCoder::GetInStreamProcessedSize(UInt64 *value)
\r
61 HRESULT CopyStream(ISequentialInStream *inStream, ISequentialOutStream *outStream, ICompressProgressInfo *progress)
\r
63 CMyComPtr<ICompressCoder> copyCoder = new NCompress::CCopyCoder;
\r
64 return copyCoder->Code(inStream, outStream, NULL, NULL, progress);
\r