add E_ABORT detection

- lz4 and lz5 are not finished...
This commit is contained in:
Tino Reichardt
2016-11-20 16:42:13 +01:00
parent 94b2bf5dec
commit 4c28e3fa11
12 changed files with 188 additions and 97 deletions

View File

@@ -9,6 +9,16 @@ int ZstdRead(void *arg, ZSTDMT_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 ZstdWrite(void *arg, ZSTDMT_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);
@@ -137,11 +159,11 @@ HRESULT CDecoder::CodeSpec(ISequentialInStream * inStream,
/* 3) decompress */
result = ZSTDMT_decompressDCtx(ctx, &rdwr);
//printf("decompress = %d / %d\n", result, ZSTDMT_error_read_fail);
if (result == (size_t)-ZSTDMT_error_read_fail)
res = E_ABORT;
else if (ZSTDMT_isError(result))
if (ZSTDMT_isError(result)) {
if (result == (size_t)-ZSTDMT_error_canceled)
return E_ABORT;
return ErrorOut(result);
}
/* 4) free resources */
ZSTDMT_freeDCtx(ctx);