From eeb8bea34c2df279307eaed922f3a89cc420316c Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 30 Mar 2015 16:36:57 +0100 Subject: Updated comments on LZ4F_getFrameInfo() --- lib/lz4frame.c | 8 ++++---- lib/lz4frame.h | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/lz4frame.c b/lib/lz4frame.c index 5683eee..5f69c95 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -918,10 +918,10 @@ LZ4F_errorCode_t LZ4F_getFrameInfo(LZ4F_decompressionContext_t decompressionCont if (dctxPtr->dStage == dstage_getHeader) { - LZ4F_errorCode_t errorCode = LZ4F_decodeHeader(dctxPtr, srcBuffer, *srcSizePtr); - if (LZ4F_isError(errorCode)) return errorCode; - *srcSizePtr = errorCode; /* nb Bytes consumed */ - *frameInfoPtr = dctxPtr->frameInfo; + size_t frameHeaderSize = LZ4F_decodeHeader(dctxPtr, srcBuffer, *srcSizePtr); + if (LZ4F_isError(frameHeaderSize)) return frameHeaderSize; + *srcSizePtr = frameHeaderSize; /* nb Bytes consumed */ + *frameInfoPtr = dctxPtr->frameInfo; /* copy into */ dctxPtr->srcExpect = NULL; return 4; /* nextSrcSizeHint : 4 == block header size */ } diff --git a/lib/lz4frame.h b/lib/lz4frame.h index 01a756a..9d12c7d 100644 --- a/lib/lz4frame.h +++ b/lib/lz4frame.h @@ -214,8 +214,12 @@ size_t LZ4F_getFrameInfo(LZ4F_decompressionContext_t dctx, * This function decodes frame header information, such as blockSize. * It is optional : you could start by calling directly LZ4F_decompress() instead. * The objective is to extract header information without starting decompression, typically for allocation purposes. + * The function will work only if srcBuffer points at the beginning of the frame, + * and *srcSizePtr is large enough to decode the whole header (typically, between 7 & 15 bytes). + * The result is copied into an LZ4F_frameInfo_t structure, which is pointed by frameInfoPtr, and must be already allocated. * 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). + * It is basically the frame header size. * You are expected to resume decompression from where it stopped (srcBuffer + *srcSizePtr) * The function result is an hint of how many srcSize bytes LZ4F_decompress() expects for next call, * or an error code which can be tested using LZ4F_isError(). -- cgit v0.12