@@ -197,6 +197,54 @@ static inline int LZ4_compressBound(size_t isize)
197197int LZ4_compress_default (const char * source , char * dest , int inputSize ,
198198 int maxOutputSize , void * wrkmem );
199199
200+ /**
201+ * LZ4_compress_fast() - As LZ4_compress_default providing an acceleration param
202+ * @source: source address of the original data
203+ * @dest: output buffer address of the compressed data
204+ * @inputSize: size of the input data. Max supported value is LZ4_MAX_INPUT_SIZE
205+ * @maxOutputSize: full or partial size of buffer 'dest'
206+ * which must be already allocated
207+ * @acceleration: acceleration factor
208+ * @wrkmem: address of the working memory.
209+ * This requires 'workmem' of LZ4_MEM_COMPRESS.
210+ *
211+ * Same as LZ4_compress_default(), but allows to select an "acceleration"
212+ * factor. The larger the acceleration value, the faster the algorithm,
213+ * but also the lesser the compression. It's a trade-off. It can be fine tuned,
214+ * with each successive value providing roughly +~3% to speed.
215+ * An acceleration value of "1" is the same as regular LZ4_compress_default()
216+ * Values <= 0 will be replaced by LZ4_ACCELERATION_DEFAULT, which is 1.
217+ *
218+ * Return: Number of bytes written into buffer 'dest'
219+ * (necessarily <= maxOutputSize) or 0 if compression fails
220+ */
221+ int LZ4_compress_fast (const char * source , char * dest , int inputSize ,
222+ int maxOutputSize , int acceleration , void * wrkmem );
223+
224+ /**
225+ * LZ4_compress_destSize() - Compress as much data as possible
226+ * from source to dest
227+ * @source: source address of the original data
228+ * @dest: output buffer address of the compressed data
229+ * @sourceSizePtr: will be modified to indicate how many bytes where read
230+ * from 'source' to fill 'dest'. New value is necessarily <= old value.
231+ * @targetDestSize: Size of buffer 'dest' which must be already allocated
232+ * @wrkmem: address of the working memory.
233+ * This requires 'workmem' of LZ4_MEM_COMPRESS.
234+ *
235+ * Reverse the logic, by compressing as much data as possible
236+ * from 'source' buffer into already allocated buffer 'dest'
237+ * of size 'targetDestSize'.
238+ * This function either compresses the entire 'source' content into 'dest'
239+ * if it's large enough, or fill 'dest' buffer completely with as much data as
240+ * possible from 'source'.
241+ *
242+ * Return: Number of bytes written into 'dest' (necessarily <= targetDestSize)
243+ * or 0 if compression fails
244+ */
245+ int LZ4_compress_destSize (const char * source , char * dest , int * sourceSizePtr ,
246+ int targetDestSize , void * wrkmem );
247+
200248/*-************************************************************************
201249 * Decompression Functions
202250 **************************************************************************/
@@ -230,7 +278,7 @@ int LZ4_decompress_fast(const char *source, char *dest, int originalSize);
230278 * @compressedSize: is the precise full size of the compressed block
231279 * @maxDecompressedSize: is the size of 'dest' buffer
232280 *
233- * Decompresses data from 'source' into 'dest'.
281+ * Decompresses data fom 'source' into 'dest'.
234282 * If the source stream is detected malformed, the function will
235283 * stop decoding and return a negative result.
236284 * This function is protected against buffer overflow exploits,
@@ -298,6 +346,94 @@ int LZ4_decompress_safe_partial(const char *source, char *dest,
298346int LZ4_compress_HC (const char * src , char * dst , int srcSize , int dstCapacity ,
299347 int compressionLevel , void * wrkmem );
300348
349+ /**
350+ * LZ4_resetStreamHC() - Init an allocated 'LZ4_streamHC_t' structure
351+ * @streamHCPtr: pointer to the 'LZ4_streamHC_t' structure
352+ * @compressionLevel: Recommended values are between 4 and 9, although any
353+ * value between 1 and LZ4HC_MAX_CLEVEL will work.
354+ * Values >LZ4HC_MAX_CLEVEL behave the same as 16.
355+ *
356+ * An LZ4_streamHC_t structure can be allocated once
357+ * and re-used multiple times.
358+ * Use this function to init an allocated `LZ4_streamHC_t` structure
359+ * and start a new compression.
360+ */
361+ void LZ4_resetStreamHC (LZ4_streamHC_t * streamHCPtr , int compressionLevel );
362+
363+ /**
364+ * LZ4_loadDictHC() - Load a static dictionary into LZ4_streamHC
365+ * @streamHCPtr: pointer to the LZ4HC_stream_t
366+ * @dictionary: dictionary to load
367+ * @dictSize: size of dictionary
368+ *
369+ * Use this function to load a static dictionary into LZ4HC_stream.
370+ * Any previous data will be forgotten, only 'dictionary'
371+ * will remain in memory.
372+ * Loading a size of 0 is allowed.
373+ *
374+ * Return : dictionary size, in bytes (necessarily <= 64 KB)
375+ */
376+ int LZ4_loadDictHC (LZ4_streamHC_t * streamHCPtr , const char * dictionary ,
377+ int dictSize );
378+
379+ /**
380+ * LZ4_compress_HC_continue() - Compress 'src' using data from previously
381+ * compressed blocks as a dictionary using the HC algorithm
382+ * @streamHCPtr: Pointer to the previous 'LZ4_streamHC_t' structure
383+ * @src: source address of the original data
384+ * @dst: output buffer address of the compressed data,
385+ * which must be already allocated
386+ * @srcSize: size of the input data. Max supported value is LZ4_MAX_INPUT_SIZE
387+ * @maxDstSize: full or partial size of buffer 'dest'
388+ * which must be already allocated
389+ *
390+ * These functions compress data in successive blocks of any size, using
391+ * previous blocks as dictionary. One key assumption is that previous
392+ * blocks (up to 64 KB) remain read-accessible while
393+ * compressing next blocks. There is an exception for ring buffers,
394+ * which can be smaller than 64 KB.
395+ * Ring buffers scenario is automatically detected and handled by
396+ * LZ4_compress_HC_continue().
397+ * Before starting compression, state must be properly initialized,
398+ * using LZ4_resetStreamHC().
399+ * A first "fictional block" can then be designated as
400+ * initial dictionary, using LZ4_loadDictHC() (Optional).
401+ * Then, use LZ4_compress_HC_continue()
402+ * to compress each successive block. Previous memory blocks
403+ * (including initial dictionary when present) must remain accessible
404+ * and unmodified during compression.
405+ * 'dst' buffer should be sized to handle worst case scenarios, using
406+ * LZ4_compressBound(), to ensure operation success.
407+ * If, for any reason, previous data blocks can't be preserved unmodified
408+ * in memory during next compression block,
409+ * you must save it to a safer memory space, using LZ4_saveDictHC().
410+ * Return value of LZ4_saveDictHC() is the size of dictionary
411+ * effectively saved into 'safeBuffer'.
412+ *
413+ * Return: Number of bytes written into buffer 'dst' or 0 if compression fails
414+ */
415+ int LZ4_compress_HC_continue (LZ4_streamHC_t * streamHCPtr , const char * src ,
416+ char * dst , int srcSize , int maxDstSize );
417+
418+ /**
419+ * LZ4_saveDictHC() - Save static dictionary from LZ4HC_stream
420+ * @streamHCPtr: pointer to the 'LZ4HC_stream_t' structure
421+ * @safeBuffer: buffer to save dictionary to, must be already allocated
422+ * @maxDictSize: size of 'safeBuffer'
423+ *
424+ * If previously compressed data block is not guaranteed
425+ * to remain available at its memory location,
426+ * save it into a safer place (char *safeBuffer).
427+ * Note : you don't need to call LZ4_loadDictHC() afterwards,
428+ * dictionary is immediately usable, you can therefore call
429+ * LZ4_compress_HC_continue().
430+ *
431+ * Return : saved dictionary size in bytes (necessarily <= maxDictSize),
432+ * or 0 if error.
433+ */
434+ int LZ4_saveDictHC (LZ4_streamHC_t * streamHCPtr , char * safeBuffer ,
435+ int maxDictSize );
436+
301437/*-*********************************************
302438 * Streaming Compression Functions
303439 ***********************************************/
@@ -311,7 +447,7 @@ int LZ4_compress_HC(const char *src, char *dst, int srcSize, int dstCapacity,
311447 * Use this function to init an allocated `LZ4_stream_t` structure
312448 * and start a new compression.
313449 */
314- static __always_inline void LZ4_resetStream (LZ4_stream_t * LZ4_stream );
450+ void LZ4_resetStream (LZ4_stream_t * LZ4_stream );
315451
316452/**
317453 * LZ4_loadDict() - Load a static dictionary into LZ4_stream
@@ -347,4 +483,166 @@ int LZ4_loadDict(LZ4_stream_t *streamPtr, const char *dictionary,
347483 */
348484int LZ4_saveDict (LZ4_stream_t * streamPtr , char * safeBuffer , int dictSize );
349485
486+ /**
487+ * LZ4_compress_fast_continue() - Compress 'src' using data from previously
488+ * compressed blocks as a dictionary
489+ * @streamPtr: Pointer to the previous 'LZ4_stream_t' structure
490+ * @src: source address of the original data
491+ * @dst: output buffer address of the compressed data,
492+ * which must be already allocated
493+ * @srcSize: size of the input data. Max supported value is LZ4_MAX_INPUT_SIZE
494+ * @maxDstSize: full or partial size of buffer 'dest'
495+ * which must be already allocated
496+ * @acceleration: acceleration factor
497+ *
498+ * Compress buffer content 'src', using data from previously compressed blocks
499+ * as dictionary to improve compression ratio.
500+ * Important : Previous data blocks are assumed to still
501+ * be present and unmodified !
502+ * If maxDstSize >= LZ4_compressBound(srcSize),
503+ * compression is guaranteed to succeed, and runs faster.
504+ *
505+ * Return: Number of bytes written into buffer 'dst' or 0 if compression fails
506+ */
507+ int LZ4_compress_fast_continue (LZ4_stream_t * streamPtr , const char * src ,
508+ char * dst , int srcSize , int maxDstSize , int acceleration );
509+
510+ /**
511+ * LZ4_setStreamDecode() - Instruct where to find dictionary
512+ * @LZ4_streamDecode: the 'LZ4_streamDecode_t' structure
513+ * @dictionary: dictionary to use
514+ * @dictSize: size of dictionary
515+ *
516+ * Use this function to instruct where to find the dictionary.
517+ * Setting a size of 0 is allowed (same effect as reset).
518+ *
519+ * Return: 1 if OK, 0 if error
520+ */
521+ int LZ4_setStreamDecode (LZ4_streamDecode_t * LZ4_streamDecode ,
522+ const char * dictionary , int dictSize );
523+
524+ /**
525+ * LZ4_decompress_fast_continue() - Decompress blocks in streaming mode
526+ * @LZ4_streamDecode: the 'LZ4_streamDecode_t' structure
527+ * @source: source address of the compressed data
528+ * @dest: output buffer address of the uncompressed data
529+ * which must be already allocated
530+ * @compressedSize: is the precise full size of the compressed block
531+ * @maxDecompressedSize: is the size of 'dest' buffer
532+ *
533+ * These decoding function allows decompression of multiple blocks
534+ * in "streaming" mode.
535+ * Previously decoded blocks *must* remain available at the memory position
536+ * where they were decoded (up to 64 KB)
537+ * In the case of a ring buffers, decoding buffer must be either :
538+ * - Exactly same size as encoding buffer, with same update rule
539+ * (block boundaries at same positions) In which case,
540+ * the decoding & encoding ring buffer can have any size,
541+ * including very small ones ( < 64 KB).
542+ * - Larger than encoding buffer, by a minimum of maxBlockSize more bytes.
543+ * maxBlockSize is implementation dependent.
544+ * It's the maximum size you intend to compress into a single block.
545+ * In which case, encoding and decoding buffers do not need
546+ * to be synchronized, and encoding ring buffer can have any size,
547+ * including small ones ( < 64 KB).
548+ * - _At least_ 64 KB + 8 bytes + maxBlockSize.
549+ * In which case, encoding and decoding buffers do not need to be
550+ * synchronized, and encoding ring buffer can have any size,
551+ * including larger than decoding buffer. W
552+ * Whenever these conditions are not possible, save the last 64KB of decoded
553+ * data into a safe buffer, and indicate where it is saved
554+ * using LZ4_setStreamDecode()
555+ *
556+ * Return: number of bytes decompressed into destination buffer
557+ * (necessarily <= maxDecompressedSize)
558+ * or a negative result in case of error
559+ */
560+ int LZ4_decompress_safe_continue (LZ4_streamDecode_t * LZ4_streamDecode ,
561+ const char * source , char * dest , int compressedSize ,
562+ int maxDecompressedSize );
563+
564+ /**
565+ * LZ4_decompress_fast_continue() - Decompress blocks in streaming mode
566+ * @LZ4_streamDecode: the 'LZ4_streamDecode_t' structure
567+ * @source: source address of the compressed data
568+ * @dest: output buffer address of the uncompressed data
569+ * which must be already allocated with 'originalSize' bytes
570+ * @originalSize: is the original and therefore uncompressed size
571+ *
572+ * These decoding function allows decompression of multiple blocks
573+ * in "streaming" mode.
574+ * Previously decoded blocks *must* remain available at the memory position
575+ * where they were decoded (up to 64 KB)
576+ * In the case of a ring buffers, decoding buffer must be either :
577+ * - Exactly same size as encoding buffer, with same update rule
578+ * (block boundaries at same positions) In which case,
579+ * the decoding & encoding ring buffer can have any size,
580+ * including very small ones ( < 64 KB).
581+ * - Larger than encoding buffer, by a minimum of maxBlockSize more bytes.
582+ * maxBlockSize is implementation dependent.
583+ * It's the maximum size you intend to compress into a single block.
584+ * In which case, encoding and decoding buffers do not need
585+ * to be synchronized, and encoding ring buffer can have any size,
586+ * including small ones ( < 64 KB).
587+ * - _At least_ 64 KB + 8 bytes + maxBlockSize.
588+ * In which case, encoding and decoding buffers do not need to be
589+ * synchronized, and encoding ring buffer can have any size,
590+ * including larger than decoding buffer. W
591+ * Whenever these conditions are not possible, save the last 64KB of decoded
592+ * data into a safe buffer, and indicate where it is saved
593+ * using LZ4_setStreamDecode()
594+ *
595+ * Return: number of bytes decompressed into destination buffer
596+ * (necessarily <= maxDecompressedSize)
597+ * or a negative result in case of error
598+ */
599+ int LZ4_decompress_fast_continue (LZ4_streamDecode_t * LZ4_streamDecode ,
600+ const char * source , char * dest , int originalSize );
601+
602+ /**
603+ * LZ4_decompress_safe_usingDict() - Same as LZ4_setStreamDecode()
604+ * followed by LZ4_decompress_safe_continue()
605+ * @source: source address of the compressed data
606+ * @dest: output buffer address of the uncompressed data
607+ * which must be already allocated
608+ * @compressedSize: is the precise full size of the compressed block
609+ * @maxDecompressedSize: is the size of 'dest' buffer
610+ * @dictStart: pointer to the start of the dictionary in memory
611+ * @dictSize: size of dictionary
612+ *
613+ * These decoding function works the same as
614+ * a combination of LZ4_setStreamDecode() followed by
615+ * LZ4_decompress_safe_continue()
616+ * It is stand-alone, and don'tn eed a LZ4_streamDecode_t structure.
617+ *
618+ * Return: number of bytes decompressed into destination buffer
619+ * (necessarily <= maxDecompressedSize)
620+ * or a negative result in case of error
621+ */
622+ int LZ4_decompress_safe_usingDict (const char * source , char * dest ,
623+ int compressedSize , int maxDecompressedSize , const char * dictStart ,
624+ int dictSize );
625+
626+ /**
627+ * LZ4_decompress_fast_usingDict() - Same as LZ4_setStreamDecode()
628+ * followed by LZ4_decompress_fast_continue()
629+ * @source: source address of the compressed data
630+ * @dest: output buffer address of the uncompressed data
631+ * which must be already allocated with 'originalSize' bytes
632+ * @originalSize: is the original and therefore uncompressed size
633+ * @dictStart: pointer to the start of the dictionary in memory
634+ * @dictSize: size of dictionary
635+ *
636+ * These decoding function works the same as
637+ * a combination of LZ4_setStreamDecode() followed by
638+ * LZ4_decompress_safe_continue()
639+ * It is stand-alone, and don'tn eed a LZ4_streamDecode_t structure.
640+ *
641+ * Return: number of bytes decompressed into destination buffer
642+ * (necessarily <= maxDecompressedSize)
643+ * or a negative result in case of error
644+ */
645+ int LZ4_decompress_fast_usingDict (const char * source , char * dest ,
646+ int originalSize , const char * dictStart , int dictSize );
647+
350648#endif
0 commit comments