mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-11 10:07:11 -06:00
add E_ABORT detection
- lz4 and lz5 are not finished...
This commit is contained in:
@@ -9,6 +9,16 @@ int Lz4Read(void *arg, LZ4MT_Buffer * in)
|
||||
size_t size = in->size;
|
||||
|
||||
HRESULT res = ReadStream(x->inStream, in->buf, &size);
|
||||
|
||||
/* catch errors */
|
||||
switch (res) {
|
||||
case E_ABORT:
|
||||
return -2;
|
||||
case E_OUTOFMEMORY:
|
||||
return -3;
|
||||
}
|
||||
|
||||
/* some other error -> read_fail */
|
||||
if (res != S_OK)
|
||||
return -1;
|
||||
|
||||
@@ -28,17 +38,29 @@ int Lz4Write(void *arg, LZ4MT_Buffer * out)
|
||||
{
|
||||
UInt32 block;
|
||||
HRESULT res = x->outStream->Write((char*)out->buf + done, todo, &block);
|
||||
|
||||
/* catch errors */
|
||||
switch (res) {
|
||||
case E_ABORT:
|
||||
return -2;
|
||||
case E_OUTOFMEMORY:
|
||||
return -3;
|
||||
}
|
||||
|
||||
done += block;
|
||||
if (res == k_My_HRESULT_WritingWasCut)
|
||||
break;
|
||||
/* some other error -> write_fail */
|
||||
if (res != S_OK)
|
||||
return -1;
|
||||
|
||||
if (block == 0)
|
||||
return E_FAIL;
|
||||
return -1;
|
||||
todo -= block;
|
||||
}
|
||||
|
||||
*x->processedOut += done;
|
||||
/* we need no lock here, cause only one thread can write... */
|
||||
if (x->progress)
|
||||
x->progress->SetRatioInfo(x->processedIn, x->processedOut);
|
||||
|
||||
@@ -130,17 +152,18 @@ HRESULT CDecoder::CodeSpec(ISequentialInStream * inStream,
|
||||
rdwr.arg_read = (void *)&Rd;
|
||||
rdwr.arg_write = (void *)&Wr;
|
||||
|
||||
/* 2) create compression context */
|
||||
/* 2) create decompression context */
|
||||
LZ4MT_DCtx *ctx = LZ4MT_createDCtx(_numThreads, _inputSize);
|
||||
if (!ctx)
|
||||
return S_FALSE;
|
||||
|
||||
/* 3) compress */
|
||||
result = LZ4MT_DecompressDCtx(ctx, &rdwr);
|
||||
if (result == (size_t)-LZ4MT_error_read_fail)
|
||||
res = E_ABORT;
|
||||
else if (LZ4MT_isError(result))
|
||||
/* 3) decompress */
|
||||
result = LZ4MT_decompressDCtx(ctx, &rdwr);
|
||||
if (LZ4MT_isError(result)) {
|
||||
if (result == (size_t)-LZ4MT_error_canceled)
|
||||
return E_ABORT;
|
||||
return ErrorOut(result);
|
||||
}
|
||||
|
||||
/* 4) free resources */
|
||||
LZ4MT_freeDCtx(ctx);
|
||||
|
||||
Reference in New Issue
Block a user