Mercurial > vba-linux
comparison 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 |
comparison
equal
deleted
inserted
replaced
0:8ced16adf2e1 | 1:f9f4f1b99eed |
---|---|
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 } |