diff options
author | Alexander Mohr <alexander.m.mohr@mercedes-benz.com> | 2022-06-10 06:00:38 (GMT) |
---|---|---|
committer | Alexander Mohr <alexander.m.mohr@mercedes-benz.com> | 2022-06-10 06:00:38 (GMT) |
commit | 62f6cef564a9478b92e6dbd0faa81eaa1a90b34f (patch) | |
tree | 1c801d4a4c20dd950abecd0f173013bbb0f48af4 | |
parent | 4aeb5020c35e2464c25eb69d8bf6c7645b8faf20 (diff) | |
download | lz4-62f6cef564a9478b92e6dbd0faa81eaa1a90b34f.zip lz4-62f6cef564a9478b92e6dbd0faa81eaa1a90b34f.tar.gz lz4-62f6cef564a9478b92e6dbd0faa81eaa1a90b34f.tar.bz2 |
review: Fix review findings
This commit fixes the review findings
Signed-off-by: Alexander Mohr <alexander.m.mohr@mercedes-benz.com>
-rw-r--r-- | doc/lz4_manual.html | 12 | ||||
-rw-r--r-- | doc/lz4frame_manual.html | 37 | ||||
-rw-r--r-- | lib/lz4.c | 14 | ||||
-rw-r--r-- | lib/lz4.h | 13 | ||||
-rw-r--r-- | lib/lz4frame.c | 7 | ||||
-rw-r--r-- | lib/lz4frame.h | 5 | ||||
-rw-r--r-- | lib/lz4hc.c | 14 | ||||
-rw-r--r-- | lib/lz4hc.h | 14 |
8 files changed, 89 insertions, 27 deletions
diff --git a/doc/lz4_manual.html b/doc/lz4_manual.html index 037cfc0..13c1ae6 100644 --- a/doc/lz4_manual.html +++ b/doc/lz4_manual.html @@ -391,6 +391,18 @@ int LZ4_freeStreamDecode (LZ4_streamDecode_t* LZ4_stream); </p></pre><BR> +<pre><b>LZ4LIB_STATIC_API int LZ4_getDictSize (LZ4_stream_t* LZ4_dict, int dictSize); +</b><p> Get the size of the dictionary. This can be used for adding data without + compression to the LZ4 archive. If linked blocked mode is used the memory + of the dictionary is kept free. + This way uncompressed data does not influence the effectiveness of the + dictionary. + @param LZ4_dict Pointer to the dictionary to get the size of. + @param dictSize The maximum dictionary size. (Normally 64 KB). + @return The size of the dictionary. + +</p></pre><BR> + <pre><b></b><p> It's possible to have input and output sharing the same buffer, for highly constrained memory environments. diff --git a/doc/lz4frame_manual.html b/doc/lz4frame_manual.html index 9490b51..b47a92f 100644 --- a/doc/lz4frame_manual.html +++ b/doc/lz4frame_manual.html @@ -75,11 +75,6 @@ LZ4F_OBSOLETE_ENUM(skippableFrame) } LZ4F_frameType_t; </b></pre><BR> -<pre><b>typedef enum { - LZ4B_COMPRESSED, - LZ4B_UNCOMPRESSED, -} LZ4F_blockCompression_t; -</b></pre><BR> <pre><b>typedef struct { LZ4F_blockSizeID_t blockSizeID; </b>/* max64KB, max256KB, max1MB, max4MB; 0 == default */<b> LZ4F_blockMode_t blockMode; </b>/* LZ4F_blockLinked, LZ4F_blockIndependent; 0 == default */<b> @@ -189,22 +184,40 @@ LZ4F_errorCode_t LZ4F_freeCompressionContext(LZ4F_cctx* cctx); This value is provided by LZ4F_compressBound(). If this condition is not respected, LZ4F_compress() will fail (result is an errorCode). After an error, the state is left in a UB state, and must be re-initialized or freed. + If previously an uncompressed block was written, buffered data is flushed + before appending compressed data is continued. `cOptPtr` is optional : NULL can be provided, in which case all options are set to default. @return : number of bytes written into `dstBuffer` (it can be zero, meaning input data was just buffered). or an error code if it fails (which can be tested using LZ4F_isError()) </p></pre><BR> -<pre><b>size_t LZ4F_flush(LZ4F_cctx* cctx, +<pre><b>size_t LZ4F_uncompressedUpdate(LZ4F_cctx* cctx, + void* dstBuffer, size_t dstCapacity, + const void* srcBuffer, size_t srcSize, + const LZ4F_compressOptions_t* cOptPtr); +/*! LZ4F_flush() : + * When data must be generated and sent immediately, without waiting for a block to be completely filled, + * it's possible to call LZ4_flush(). It will immediately compress any data buffered within cctx. + * `dstCapacity` must be large enough to ensure the operation will be successful. + * `cOptPtr` is optional : it's possible to provide NULL, all options will be set to default. + * @return : nb of bytes written into dstBuffer (can be zero, when there is no data stored within cctx) + * or an error code if it fails (which can be tested using LZ4F_isError()) + * Note : LZ4F_flush() is guaranteed to be successful when dstCapacity >= LZ4F_compressBound(0, prefsPtr). + */ +size_t LZ4F_flush(LZ4F_cctx* cctx, void* dstBuffer, size_t dstCapacity, const LZ4F_compressOptions_t* cOptPtr); -</b><p> When data must be generated and sent immediately, without waiting for a block to be completely filled, - it's possible to call LZ4_flush(). It will immediately compress any data buffered within cctx. - `dstCapacity` must be large enough to ensure the operation will be successful. - `cOptPtr` is optional : it's possible to provide NULL, all options will be set to default. - @return : nb of bytes written into dstBuffer (can be zero, when there is no data stored within cctx) +</b><p> LZ4F_uncompressedUpdate() can be called repetitively to add as much data uncompressed data as necessary. + Important rule: dstCapacity MUST be large enough to store the entire source buffer as + no compression is done for this operation + If this condition is not respected, LZ4F_uncompressedUpdate() will fail (result is an errorCode). + After an error, the state is left in a UB state, and must be re-initialized or freed. + If previously a compressed block was written, buffered data is flushed + before appending uncompressed data is continued. + `cOptPtr` is optional : NULL can be provided, in which case all options are set to default. + @return : number of bytes written into `dstBuffer` (it can be zero, meaning input data was just buffered). or an error code if it fails (which can be tested using LZ4F_isError()) - Note : LZ4F_flush() is guaranteed to be successful when dstCapacity >= LZ4F_compressBound(0, prefsPtr). </p></pre><BR> @@ -1679,7 +1679,17 @@ int LZ4_compress_forceExtDict (LZ4_stream_t* LZ4_dict, const char* source, char* return result; } -int LZ4_DictSize (LZ4_stream_t* LZ4_dict, int dictSize) +/*! LZ4_getDictSize(): + * Get the size of the dictionary. This can be used for adding data without + * compression to the LZ4 archive. If linked blocked mode is used the memory + * of the dictionary is kept free. + * This way uncompressed data does not influence the effectiveness of the + * dictionary. + * @param LZ4_dict Pointer to the dictionary to get the size of. + * @param dictSize The maximum dictionary size. (Normally 64 KB). + * @return The size of the dictionary. + */ +int LZ4_getDictSize (LZ4_stream_t* LZ4_dict, int dictSize) { LZ4_stream_t_internal* const dict = &LZ4_dict->internal_donotuse; @@ -1699,7 +1709,7 @@ int LZ4_DictSize (LZ4_stream_t* LZ4_dict, int dictSize) int LZ4_saveDict (LZ4_stream_t* LZ4_dict, char* safeBuffer, int dictSize) { LZ4_stream_t_internal* const dict = &LZ4_dict->internal_donotuse; - dictSize = LZ4_DictSize(LZ4_dict, dictSize); + dictSize = LZ4_getDictSize(LZ4_dict, dictSize); DEBUGLOG(5, "LZ4_saveDict : dictSize=%i, safeBuffer=%p", dictSize, safeBuffer); if (safeBuffer == NULL) assert(dictSize == 0); @@ -346,8 +346,6 @@ LZ4LIB_API int LZ4_loadDict (LZ4_stream_t* streamPtr, const char* dictionary, in */ LZ4LIB_API int LZ4_compress_fast_continue (LZ4_stream_t* streamPtr, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration); -LZ4LIB_API int LZ4_DictSize (LZ4_stream_t* LZ4_dict, int dictSize); - /*! LZ4_saveDict() : * If last 64KB data cannot be guaranteed to remain available at its current memory location, * save it into a safer place (char* safeBuffer). @@ -511,6 +509,17 @@ LZ4LIB_STATIC_API int LZ4_compress_fast_extState_fastReset (void* state, const c */ LZ4LIB_STATIC_API void LZ4_attach_dictionary(LZ4_stream_t* workingStream, const LZ4_stream_t* dictionaryStream); +/*! LZ4_getDictSize(): + * Get the size of the dictionary. This can be used for adding data without + * compression to the LZ4 archive. If linked blocked mode is used the memory + * of the dictionary is kept free. + * This way uncompressed data does not influence the effectiveness of the + * dictionary. + * @param LZ4_dict Pointer to the dictionary to get the size of. + * @param dictSize The maximum dictionary size. (Normally 64 KB). + * @return The size of the dictionary. + */ +LZ4LIB_STATIC_API int LZ4_getDictSize (LZ4_stream_t* LZ4_dict, int dictSize); /*! In-place compression and decompression * diff --git a/lib/lz4frame.c b/lib/lz4frame.c index bcf9629..0c78a1f 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -221,6 +221,9 @@ static const size_t BFSize = LZ4F_BLOCK_CHECKSUM_SIZE; /* block footer : checks /*-************************************ * Structures and local types **************************************/ + +typedef enum { LZ4B_COMPRESSED, LZ4B_UNCOMPRESSED} LZ4F_blockCompression_t; + typedef struct LZ4F_cctx_s { LZ4F_preferences_t prefs; @@ -854,8 +857,8 @@ static int LZ4F_localSaveDict(LZ4F_cctx_t* cctxPtr) static int LZ4F_localDictSize(LZ4F_cctx_t* cctxPtr) { if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN) - return LZ4_DictSize ((LZ4_stream_t*)(cctxPtr->lz4CtxPtr), LZ4F_maxDictSize()); - return LZ4_DictHCSize ((LZ4_streamHC_t*)(cctxPtr->lz4CtxPtr), LZ4F_maxDictSize()); + return LZ4_getDictSize ((LZ4_stream_t*)(cctxPtr->lz4CtxPtr), LZ4F_maxDictSize()); + return LZ4_getDictHCSize ((LZ4_streamHC_t*)(cctxPtr->lz4CtxPtr), LZ4F_maxDictSize()); } typedef enum { notDone, fromTmpBuffer, fromSrcBuffer } LZ4F_lastBlockStatus; diff --git a/lib/lz4frame.h b/lib/lz4frame.h index 18d33e1..20bfb8b 100644 --- a/lib/lz4frame.h +++ b/lib/lz4frame.h @@ -160,11 +160,6 @@ typedef enum { LZ4F_OBSOLETE_ENUM(skippableFrame) } LZ4F_frameType_t; -typedef enum { - LZ4B_COMPRESSED, - LZ4B_UNCOMPRESSED -} LZ4F_blockCompression_t; - #ifdef LZ4F_ENABLE_OBSOLETE_ENUMS typedef LZ4F_blockSizeID_t blockSizeID_t; typedef LZ4F_blockMode_t blockMode_t; diff --git a/lib/lz4hc.c b/lib/lz4hc.c index da806ef..bf6294d 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -1154,7 +1154,17 @@ int LZ4_compress_HC_continue_destSize (LZ4_streamHC_t* LZ4_streamHCPtr, const ch return LZ4_compressHC_continue_generic(LZ4_streamHCPtr, src, dst, srcSizePtr, targetDestSize, fillOutput); } -int LZ4_DictHCSize(LZ4_streamHC_t* LZ4_streamHCPtr, int dictSize) { +/*! LZ4_getDictHCSize(): + * Get the size of the dictionary. This can be used for adding data without + * compression to the LZ4 archive. If linked blocked mode is used the memory + * of the dictionary is kept free. + * This way uncompressed data does not influence the effectiveness of the + * dictionary. + * @param LZ4_dict Pointer to the dictionary to get the size of. + * @param dictSize The maximum dictionary size. (Normally 64 KB). + * @return The size of the dictionary. + */ +int LZ4_getDictHCSize(LZ4_streamHC_t* LZ4_streamHCPtr, int dictSize) { LZ4HC_CCtx_internal* const streamPtr = &LZ4_streamHCPtr->internal_donotuse; int const prefixSize = (int)(streamPtr->end - (streamPtr->base + streamPtr->dictLimit)); DEBUGLOG(5, "LZ4_saveDictHC(%p, %p, %d)", LZ4_streamHCPtr, safeBuffer, dictSize); @@ -1174,7 +1184,7 @@ int LZ4_DictHCSize(LZ4_streamHC_t* LZ4_streamHCPtr, int dictSize) { int LZ4_saveDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, char* safeBuffer, int dictSize) { LZ4HC_CCtx_internal* const streamPtr = &LZ4_streamHCPtr->internal_donotuse; - dictSize = LZ4_DictHCSize(LZ4_streamHCPtr, dictSize); + dictSize = LZ4_getDictHCSize(LZ4_streamHCPtr, dictSize); if (safeBuffer == NULL) assert(dictSize == 0); if (dictSize > 0) memmove(safeBuffer, streamPtr->end - dictSize, dictSize); diff --git a/lib/lz4hc.h b/lib/lz4hc.h index 11671dc..e62dfa7 100644 --- a/lib/lz4hc.h +++ b/lib/lz4hc.h @@ -173,8 +173,6 @@ LZ4LIB_API int LZ4_compress_HC_continue_destSize(LZ4_streamHC_t* LZ4_streamHCPtr const char* src, char* dst, int* srcSizePtr, int targetDstSize); -LZ4LIB_API int LZ4_DictHCSize(LZ4_streamHC_t* LZ4_streamHCPtr, int dictSize); - LZ4LIB_API int LZ4_saveDictHC (LZ4_streamHC_t* streamHCPtr, char* safeBuffer, int maxDictSize); @@ -407,6 +405,18 @@ LZ4LIB_STATIC_API void LZ4_attach_HC_dictionary( LZ4_streamHC_t *working_stream, const LZ4_streamHC_t *dictionary_stream); +/*! LZ4_getDictHCSize(): + * Get the size of the dictionary. This can be used for adding data without + * compression to the LZ4 archive. If linked blocked mode is used the memory + * of the dictionary is kept free. + * This way uncompressed data does not influence the effectiveness of the + * dictionary. + * @param LZ4_dict Pointer to the dictionary to get the size of. + * @param dictSize The maximum dictionary size. (Normally 64 KB). + * @return The size of the dictionary. + */ +LZ4LIB_STATIC_API int LZ4_getDictHCSize(LZ4_streamHC_t* LZ4_streamHCPtr, int dictSize); + #if defined (__cplusplus) } #endif |