From 6bede08aa42acd3391bb3a2bee4a0fded9363be5 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sat, 13 Sep 2014 14:40:35 +0100 Subject: LZ4F_getFrameInfo() : provides srcSize hint like LZ4F_decompress() --- lz4frame.c | 9 ++++++--- lz4frame.h | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lz4frame.c b/lz4frame.c index 1be6cff..4996d28 100644 --- a/lz4frame.c +++ b/lz4frame.c @@ -733,7 +733,9 @@ typedef enum { dstage_getHeader=0, dstage_storeHeader, dstage_decodeHeader, * The objective is to extract header information without starting decompression, typically for allocation purposes. * LZ4F_getFrameInfo() can also be used *after* starting decompression, on a valid LZ4F_decompressionContext_t. * The number of bytes read from srcBuffer will be provided within *srcSizePtr (necessarily <= original value). - * The function result is an error code which can be tested using LZ4F_isError(). + * You are expected to resume decompression from where it stopped (srcBuffer + *srcSizePtr) + * The function result is an hint of the better srcSize to use for next call to LZ4F_decompress. + * or an error code which can be tested using LZ4F_isError(). */ LZ4F_errorCode_t LZ4F_getFrameInfo(LZ4F_decompressionContext_t decompressionContext, LZ4F_frameInfo_t* frameInfoPtr, const void* srcBuffer, size_t* srcSizePtr) { @@ -745,14 +747,15 @@ LZ4F_errorCode_t LZ4F_getFrameInfo(LZ4F_decompressionContext_t decompressionCont if (LZ4F_isError(errorCode)) return errorCode; *srcSizePtr = errorCode; *frameInfoPtr = dctxPtr->frameInfo; + dctxPtr->srcExpect = (BYTE*)srcBuffer + errorCode; dctxPtr->dStage = dstage_getCBlockSize; - return OK_NoError; + return 4; } /* frameInfo already decoded */ *srcSizePtr = 0; *frameInfoPtr = dctxPtr->frameInfo; - return OK_NoError; + return 0; } diff --git a/lz4frame.h b/lz4frame.h index 4c8dd86..40f5e3f 100644 --- a/lz4frame.h +++ b/lz4frame.h @@ -223,7 +223,9 @@ size_t LZ4F_getFrameInfo(LZ4F_decompressionContext_t decompressionContext, LZ4F_ * The objective is to extract header information without starting decompression, typically for allocation purposes. * LZ4F_getFrameInfo() can also be used *after* starting decompression, on a valid LZ4F_decompressionContext_t. * The number of bytes read from srcBuffer will be provided within *srcSizePtr (necessarily <= original value). - * The function result is an error code which can be tested using LZ4F_isError(). + * You are expected to resume decompression from where it stopped (srcBuffer + *srcSizePtr) + * The function result is an hint of the better srcSize to use for next call to LZ4F_decompress. + * or an error code which can be tested using LZ4F_isError(). */ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, void* dstBuffer, size_t* dstSizePtr, const void* srcBuffer, size_t* srcSizePtr, const LZ4F_decompressOptions_t* decompressOptionsPtr); -- cgit v0.12