other-licenses/7zstub/src/7zip/Compress/Copy/CopyCoder.cpp

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:6935bea3a500
1 // Compress/CopyCoder.cpp
2
3 #include "StdAfx.h"
4
5 #include "CopyCoder.h"
6 #include "../../../Common/Alloc.h"
7 #include "../../Common/StreamUtils.h"
8
9 namespace NCompress {
10
11 static const UInt32 kBufferSize = 1 << 17;
12
13 CCopyCoder::~CCopyCoder()
14 {
15 ::MidFree(_buffer);
16 }
17
18 STDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream,
19 ISequentialOutStream *outStream,
20 const UInt64 *inSize, const UInt64 *outSize,
21 ICompressProgressInfo *progress)
22 {
23 if (_buffer == 0)
24 {
25 _buffer = (Byte *)::MidAlloc(kBufferSize);
26 if (_buffer == 0)
27 return E_OUTOFMEMORY;
28 }
29
30 TotalSize = 0;
31 while(true)
32 {
33 UInt32 realProcessedSize;
34 UInt32 size = kBufferSize;
35 if (outSize != 0)
36 if (size > *outSize - TotalSize)
37 size = (UInt32)(*outSize - TotalSize);
38 RINOK(inStream->Read(_buffer, size, &realProcessedSize));
39 if(realProcessedSize == 0)
40 break;
41 RINOK(WriteStream(outStream, _buffer, realProcessedSize, NULL));
42 TotalSize += realProcessedSize;
43 if (progress != NULL)
44 {
45 RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize));
46 }
47 }
48 return S_OK;
49 }
50
51 }
52

mercurial