mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-10 06:07:07 -06:00
15.05
This commit is contained in:
committed by
Kornel Lesiński
parent
0713a3ab80
commit
54490d51d5
@@ -4,17 +4,15 @@
|
||||
|
||||
#include "../../../C/Alloc.h"
|
||||
|
||||
#include "../Common/StreamUtils.h"
|
||||
|
||||
#include "CopyCoder.h"
|
||||
|
||||
namespace NCompress {
|
||||
|
||||
static const UInt32 kBufferSize = 1 << 17;
|
||||
static const UInt32 kBufSize = 1 << 17;
|
||||
|
||||
CCopyCoder::~CCopyCoder()
|
||||
{
|
||||
::MidFree(_buffer);
|
||||
::MidFree(_buf);
|
||||
}
|
||||
|
||||
STDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream,
|
||||
@@ -22,35 +20,78 @@ STDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream,
|
||||
const UInt64 * /* inSize */, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
if (!_buffer)
|
||||
if (!_buf)
|
||||
{
|
||||
_buffer = (Byte *)::MidAlloc(kBufferSize);
|
||||
if (!_buffer)
|
||||
_buf = (Byte *)::MidAlloc(kBufSize);
|
||||
if (!_buf)
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
TotalSize = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
UInt32 size = kBufferSize;
|
||||
UInt32 size = kBufSize;
|
||||
if (outSize && size > *outSize - TotalSize)
|
||||
size = (UInt32)(*outSize - TotalSize);
|
||||
RINOK(inStream->Read(_buffer, size, &size));
|
||||
if (size == 0)
|
||||
break;
|
||||
return S_OK;
|
||||
|
||||
HRESULT readRes = inStream->Read(_buf, size, &size);
|
||||
|
||||
if (size == 0)
|
||||
return readRes;
|
||||
|
||||
if (outStream)
|
||||
{
|
||||
RINOK(WriteStream(outStream, _buffer, size));
|
||||
UInt32 pos = 0;
|
||||
do
|
||||
{
|
||||
UInt32 curSize = size - pos;
|
||||
HRESULT res = outStream->Write(_buf + pos, curSize, &curSize);
|
||||
pos += curSize;
|
||||
TotalSize += curSize;
|
||||
RINOK(res);
|
||||
if (curSize == 0)
|
||||
return E_FAIL;
|
||||
}
|
||||
while (pos < size);
|
||||
}
|
||||
TotalSize += size;
|
||||
else
|
||||
TotalSize += size;
|
||||
|
||||
RINOK(readRes);
|
||||
|
||||
if (progress)
|
||||
{
|
||||
RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
STDMETHODIMP CCopyCoder::SetInStream(ISequentialInStream *inStream)
|
||||
{
|
||||
_inStream = inStream;
|
||||
TotalSize = 0;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CCopyCoder::ReleaseInStream()
|
||||
{
|
||||
_inStream.Release();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CCopyCoder::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
UInt32 realProcessedSize = 0;
|
||||
HRESULT res = _inStream->Read(data, size, &realProcessedSize);
|
||||
TotalSize += realProcessedSize;
|
||||
if (processedSize)
|
||||
*processedSize = realProcessedSize;
|
||||
return res;
|
||||
}
|
||||
|
||||
STDMETHODIMP CCopyCoder::GetInStreamProcessedSize(UInt64 *value)
|
||||
{
|
||||
*value = TotalSize;
|
||||
|
||||
Reference in New Issue
Block a user