michael@0: // Compress/CopyCoder.cpp michael@0: michael@0: #include "StdAfx.h" michael@0: michael@0: #include "CopyCoder.h" michael@0: #include "../../../Common/Alloc.h" michael@0: #include "../../Common/StreamUtils.h" michael@0: michael@0: namespace NCompress { michael@0: michael@0: static const UInt32 kBufferSize = 1 << 17; michael@0: michael@0: CCopyCoder::~CCopyCoder() michael@0: { michael@0: ::MidFree(_buffer); michael@0: } michael@0: michael@0: STDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream, michael@0: ISequentialOutStream *outStream, michael@0: const UInt64 *inSize, const UInt64 *outSize, michael@0: ICompressProgressInfo *progress) michael@0: { michael@0: if (_buffer == 0) michael@0: { michael@0: _buffer = (Byte *)::MidAlloc(kBufferSize); michael@0: if (_buffer == 0) michael@0: return E_OUTOFMEMORY; michael@0: } michael@0: michael@0: TotalSize = 0; michael@0: while(true) michael@0: { michael@0: UInt32 realProcessedSize; michael@0: UInt32 size = kBufferSize; michael@0: if (outSize != 0) michael@0: if (size > *outSize - TotalSize) michael@0: size = (UInt32)(*outSize - TotalSize); michael@0: RINOK(inStream->Read(_buffer, size, &realProcessedSize)); michael@0: if(realProcessedSize == 0) michael@0: break; michael@0: RINOK(WriteStream(outStream, _buffer, realProcessedSize, NULL)); michael@0: TotalSize += realProcessedSize; michael@0: if (progress != NULL) michael@0: { michael@0: RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize)); michael@0: } michael@0: } michael@0: return S_OK; michael@0: } michael@0: michael@0: } michael@0: