| OLD | NEW |
| (Empty) |
| 1 // Compress/CopyCoder.cpp | |
| 2 | |
| 3 #include "StdAfx.h" | |
| 4 | |
| 5 extern "C" | |
| 6 { | |
| 7 #include "../../../C/Alloc.h" | |
| 8 } | |
| 9 | |
| 10 #include "../Common/StreamUtils.h" | |
| 11 | |
| 12 #include "CopyCoder.h" | |
| 13 | |
| 14 namespace NCompress { | |
| 15 | |
| 16 static const UInt32 kBufferSize = 1 << 17; | |
| 17 | |
| 18 CCopyCoder::~CCopyCoder() | |
| 19 { | |
| 20 ::MidFree(_buffer); | |
| 21 } | |
| 22 | |
| 23 STDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream, | |
| 24 ISequentialOutStream *outStream, | |
| 25 const UInt64 * /* inSize */, const UInt64 *outSize, | |
| 26 ICompressProgressInfo *progress) | |
| 27 { | |
| 28 if (_buffer == 0) | |
| 29 { | |
| 30 _buffer = (Byte *)::MidAlloc(kBufferSize); | |
| 31 if (_buffer == 0) | |
| 32 return E_OUTOFMEMORY; | |
| 33 } | |
| 34 | |
| 35 TotalSize = 0; | |
| 36 for (;;) | |
| 37 { | |
| 38 UInt32 realProcessedSize; | |
| 39 UInt32 size = kBufferSize; | |
| 40 if (outSize != 0) | |
| 41 if (size > *outSize - TotalSize) | |
| 42 size = (UInt32)(*outSize - TotalSize); | |
| 43 RINOK(inStream->Read(_buffer, size, &realProcessedSize)); | |
| 44 if (realProcessedSize == 0) | |
| 45 break; | |
| 46 RINOK(WriteStream(outStream, _buffer, realProcessedSize)); | |
| 47 TotalSize += realProcessedSize; | |
| 48 if (progress != NULL) | |
| 49 { | |
| 50 RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize)); | |
| 51 } | |
| 52 } | |
| 53 return S_OK; | |
| 54 } | |
| 55 | |
| 56 STDMETHODIMP CCopyCoder::GetInStreamProcessedSize(UInt64 *value) | |
| 57 { | |
| 58 *value = TotalSize; | |
| 59 return S_OK; | |
| 60 } | |
| 61 | |
| 62 } | |
| OLD | NEW |