14e1a33b1SSven Schmidt /* LZ4 Kernel Interface
2cffb78b0SKyungsik Lee *
3cffb78b0SKyungsik Lee * Copyright (C) 2013, LG Electronics, Kyungsik Lee <[email protected]>
44e1a33b1SSven Schmidt * Copyright (C) 2016, Sven Schmidt <[email protected]>
5cffb78b0SKyungsik Lee *
6cffb78b0SKyungsik Lee * This program is free software; you can redistribute it and/or modify
7cffb78b0SKyungsik Lee * it under the terms of the GNU General Public License version 2 as
8cffb78b0SKyungsik Lee * published by the Free Software Foundation.
94e1a33b1SSven Schmidt *
104e1a33b1SSven Schmidt * This file is based on the original header file
114e1a33b1SSven Schmidt * for LZ4 - Fast LZ compression algorithm.
124e1a33b1SSven Schmidt *
134e1a33b1SSven Schmidt * LZ4 - Fast LZ compression algorithm
144e1a33b1SSven Schmidt * Copyright (C) 2011-2016, Yann Collet.
154e1a33b1SSven Schmidt * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
164e1a33b1SSven Schmidt * Redistribution and use in source and binary forms, with or without
174e1a33b1SSven Schmidt * modification, are permitted provided that the following conditions are
184e1a33b1SSven Schmidt * met:
194e1a33b1SSven Schmidt * * Redistributions of source code must retain the above copyright
204e1a33b1SSven Schmidt * notice, this list of conditions and the following disclaimer.
214e1a33b1SSven Schmidt * * Redistributions in binary form must reproduce the above
224e1a33b1SSven Schmidt * copyright notice, this list of conditions and the following disclaimer
234e1a33b1SSven Schmidt * in the documentation and/or other materials provided with the
244e1a33b1SSven Schmidt * distribution.
254e1a33b1SSven Schmidt * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
264e1a33b1SSven Schmidt * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
274e1a33b1SSven Schmidt * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
284e1a33b1SSven Schmidt * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
294e1a33b1SSven Schmidt * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
304e1a33b1SSven Schmidt * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
314e1a33b1SSven Schmidt * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
324e1a33b1SSven Schmidt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
334e1a33b1SSven Schmidt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
344e1a33b1SSven Schmidt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
354e1a33b1SSven Schmidt * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
364e1a33b1SSven Schmidt * You can contact the author at :
374e1a33b1SSven Schmidt * - LZ4 homepage : http://www.lz4.org
384e1a33b1SSven Schmidt * - LZ4 source repository : https://github.com/lz4/lz4
39cffb78b0SKyungsik Lee */
404e1a33b1SSven Schmidt
414e1a33b1SSven Schmidt #ifndef __LZ4_H__
424e1a33b1SSven Schmidt #define __LZ4_H__
434e1a33b1SSven Schmidt
444e1a33b1SSven Schmidt #include <linux/types.h>
454e1a33b1SSven Schmidt #include <linux/string.h> /* memset, memcpy */
464e1a33b1SSven Schmidt
474e1a33b1SSven Schmidt /*-************************************************************************
484e1a33b1SSven Schmidt * CONSTANTS
494e1a33b1SSven Schmidt **************************************************************************/
504e1a33b1SSven Schmidt /*
514e1a33b1SSven Schmidt * LZ4_MEMORY_USAGE :
524e1a33b1SSven Schmidt * Memory usage formula : N->2^N Bytes
534e1a33b1SSven Schmidt * (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; etc.)
544e1a33b1SSven Schmidt * Increasing memory usage improves compression ratio
554e1a33b1SSven Schmidt * Reduced memory usage can improve speed, due to cache effect
564e1a33b1SSven Schmidt * Default value is 14, for 16KB, which nicely fits into Intel x86 L1 cache
574e1a33b1SSven Schmidt */
584e1a33b1SSven Schmidt #define LZ4_MEMORY_USAGE 14
594e1a33b1SSven Schmidt
604e1a33b1SSven Schmidt #define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */
614e1a33b1SSven Schmidt #define LZ4_COMPRESSBOUND(isize) (\
624e1a33b1SSven Schmidt (unsigned int)(isize) > (unsigned int)LZ4_MAX_INPUT_SIZE \
634e1a33b1SSven Schmidt ? 0 \
644e1a33b1SSven Schmidt : (isize) + ((isize)/255) + 16)
654e1a33b1SSven Schmidt
664e1a33b1SSven Schmidt #define LZ4_ACCELERATION_DEFAULT 1
674e1a33b1SSven Schmidt #define LZ4_HASHLOG (LZ4_MEMORY_USAGE-2)
684e1a33b1SSven Schmidt #define LZ4_HASHTABLESIZE (1 << LZ4_MEMORY_USAGE)
694e1a33b1SSven Schmidt #define LZ4_HASH_SIZE_U32 (1 << LZ4_HASHLOG)
704e1a33b1SSven Schmidt
714e1a33b1SSven Schmidt #define LZ4HC_MIN_CLEVEL 3
724e1a33b1SSven Schmidt #define LZ4HC_DEFAULT_CLEVEL 9
734e1a33b1SSven Schmidt #define LZ4HC_MAX_CLEVEL 16
744e1a33b1SSven Schmidt
754e1a33b1SSven Schmidt #define LZ4HC_DICTIONARY_LOGSIZE 16
764e1a33b1SSven Schmidt #define LZ4HC_MAXD (1<<LZ4HC_DICTIONARY_LOGSIZE)
774e1a33b1SSven Schmidt #define LZ4HC_MAXD_MASK (LZ4HC_MAXD - 1)
784e1a33b1SSven Schmidt #define LZ4HC_HASH_LOG (LZ4HC_DICTIONARY_LOGSIZE - 1)
794e1a33b1SSven Schmidt #define LZ4HC_HASHTABLESIZE (1 << LZ4HC_HASH_LOG)
804e1a33b1SSven Schmidt #define LZ4HC_HASH_MASK (LZ4HC_HASHTABLESIZE - 1)
814e1a33b1SSven Schmidt
824e1a33b1SSven Schmidt /*-************************************************************************
834e1a33b1SSven Schmidt * STREAMING CONSTANTS AND STRUCTURES
844e1a33b1SSven Schmidt **************************************************************************/
854e1a33b1SSven Schmidt #define LZ4_STREAMSIZE_U64 ((1 << (LZ4_MEMORY_USAGE - 3)) + 4)
864e1a33b1SSven Schmidt #define LZ4_STREAMSIZE (LZ4_STREAMSIZE_U64 * sizeof(unsigned long long))
874e1a33b1SSven Schmidt
884e1a33b1SSven Schmidt #define LZ4_STREAMHCSIZE 262192
894e1a33b1SSven Schmidt #define LZ4_STREAMHCSIZE_SIZET (262192 / sizeof(size_t))
904e1a33b1SSven Schmidt
914e1a33b1SSven Schmidt #define LZ4_STREAMDECODESIZE_U64 4
924e1a33b1SSven Schmidt #define LZ4_STREAMDECODESIZE (LZ4_STREAMDECODESIZE_U64 * \
934e1a33b1SSven Schmidt sizeof(unsigned long long))
94cffb78b0SKyungsik Lee
95cffb78b0SKyungsik Lee /*
964e1a33b1SSven Schmidt * LZ4_stream_t - information structure to track an LZ4 stream.
97cffb78b0SKyungsik Lee */
984e1a33b1SSven Schmidt typedef struct {
994e1a33b1SSven Schmidt uint32_t hashTable[LZ4_HASH_SIZE_U32];
1004e1a33b1SSven Schmidt uint32_t currentOffset;
1014e1a33b1SSven Schmidt uint32_t initCheck;
1024e1a33b1SSven Schmidt const uint8_t *dictionary;
1034e1a33b1SSven Schmidt uint8_t *bufferStart;
1044e1a33b1SSven Schmidt uint32_t dictSize;
1054e1a33b1SSven Schmidt } LZ4_stream_t_internal;
1064e1a33b1SSven Schmidt typedef union {
1074e1a33b1SSven Schmidt unsigned long long table[LZ4_STREAMSIZE_U64];
1084e1a33b1SSven Schmidt LZ4_stream_t_internal internal_donotuse;
1094e1a33b1SSven Schmidt } LZ4_stream_t;
1104e1a33b1SSven Schmidt
1114e1a33b1SSven Schmidt /*
1124e1a33b1SSven Schmidt * LZ4_streamHC_t - information structure to track an LZ4HC stream.
1134e1a33b1SSven Schmidt */
1144e1a33b1SSven Schmidt typedef struct {
1154e1a33b1SSven Schmidt unsigned int hashTable[LZ4HC_HASHTABLESIZE];
1164e1a33b1SSven Schmidt unsigned short chainTable[LZ4HC_MAXD];
1174e1a33b1SSven Schmidt /* next block to continue on current prefix */
1184e1a33b1SSven Schmidt const unsigned char *end;
1194e1a33b1SSven Schmidt /* All index relative to this position */
1204e1a33b1SSven Schmidt const unsigned char *base;
1214e1a33b1SSven Schmidt /* alternate base for extDict */
1224e1a33b1SSven Schmidt const unsigned char *dictBase;
1234e1a33b1SSven Schmidt /* below that point, need extDict */
1244e1a33b1SSven Schmidt unsigned int dictLimit;
1254e1a33b1SSven Schmidt /* below that point, no more dict */
1264e1a33b1SSven Schmidt unsigned int lowLimit;
1274e1a33b1SSven Schmidt /* index from which to continue dict update */
1284e1a33b1SSven Schmidt unsigned int nextToUpdate;
1294e1a33b1SSven Schmidt unsigned int compressionLevel;
1304e1a33b1SSven Schmidt } LZ4HC_CCtx_internal;
1314e1a33b1SSven Schmidt typedef union {
1324e1a33b1SSven Schmidt size_t table[LZ4_STREAMHCSIZE_SIZET];
1334e1a33b1SSven Schmidt LZ4HC_CCtx_internal internal_donotuse;
1344e1a33b1SSven Schmidt } LZ4_streamHC_t;
1354e1a33b1SSven Schmidt
1364e1a33b1SSven Schmidt /*
1374e1a33b1SSven Schmidt * LZ4_streamDecode_t - information structure to track an
1384e1a33b1SSven Schmidt * LZ4 stream during decompression.
1394e1a33b1SSven Schmidt *
1404e1a33b1SSven Schmidt * init this structure using LZ4_setStreamDecode (or memset()) before first use
1414e1a33b1SSven Schmidt */
1424e1a33b1SSven Schmidt typedef struct {
1434e1a33b1SSven Schmidt const uint8_t *externalDict;
1444e1a33b1SSven Schmidt size_t extDictSize;
1454e1a33b1SSven Schmidt const uint8_t *prefixEnd;
1464e1a33b1SSven Schmidt size_t prefixSize;
1474e1a33b1SSven Schmidt } LZ4_streamDecode_t_internal;
1484e1a33b1SSven Schmidt typedef union {
1494e1a33b1SSven Schmidt unsigned long long table[LZ4_STREAMDECODESIZE_U64];
1504e1a33b1SSven Schmidt LZ4_streamDecode_t_internal internal_donotuse;
1514e1a33b1SSven Schmidt } LZ4_streamDecode_t;
1524e1a33b1SSven Schmidt
1534e1a33b1SSven Schmidt /*-************************************************************************
1544e1a33b1SSven Schmidt * SIZE OF STATE
1554e1a33b1SSven Schmidt **************************************************************************/
1564e1a33b1SSven Schmidt #define LZ4_MEM_COMPRESS LZ4_STREAMSIZE
1574e1a33b1SSven Schmidt #define LZ4HC_MEM_COMPRESS LZ4_STREAMHCSIZE
1584e1a33b1SSven Schmidt
1594e1a33b1SSven Schmidt /*-************************************************************************
1604e1a33b1SSven Schmidt * Compression Functions
1614e1a33b1SSven Schmidt **************************************************************************/
1624e1a33b1SSven Schmidt
1634e1a33b1SSven Schmidt /**
1644e1a33b1SSven Schmidt * LZ4_compressBound() - Max. output size in worst case szenarios
1654e1a33b1SSven Schmidt * @isize: Size of the input data
1664e1a33b1SSven Schmidt *
1674e1a33b1SSven Schmidt * Return: Max. size LZ4 may output in a "worst case" szenario
1684e1a33b1SSven Schmidt * (data not compressible)
1694e1a33b1SSven Schmidt */
LZ4_compressBound(size_t isize)1704e1a33b1SSven Schmidt static inline int LZ4_compressBound(size_t isize)
171cffb78b0SKyungsik Lee {
1724e1a33b1SSven Schmidt return LZ4_COMPRESSBOUND(isize);
173cffb78b0SKyungsik Lee }
174cffb78b0SKyungsik Lee
1754e1a33b1SSven Schmidt /**
1764e1a33b1SSven Schmidt * LZ4_compress_default() - Compress data from source to dest
1774e1a33b1SSven Schmidt * @source: source address of the original data
1784e1a33b1SSven Schmidt * @dest: output buffer address of the compressed data
1794e1a33b1SSven Schmidt * @inputSize: size of the input data. Max supported value is LZ4_MAX_INPUT_SIZE
1804e1a33b1SSven Schmidt * @maxOutputSize: full or partial size of buffer 'dest'
1814e1a33b1SSven Schmidt * which must be already allocated
1824e1a33b1SSven Schmidt * @wrkmem: address of the working memory.
1834e1a33b1SSven Schmidt * This requires 'workmem' of LZ4_MEM_COMPRESS.
1844e1a33b1SSven Schmidt *
1854e1a33b1SSven Schmidt * Compresses 'sourceSize' bytes from buffer 'source'
1864e1a33b1SSven Schmidt * into already allocated 'dest' buffer of size 'maxOutputSize'.
1874e1a33b1SSven Schmidt * Compression is guaranteed to succeed if
1884e1a33b1SSven Schmidt * 'maxOutputSize' >= LZ4_compressBound(inputSize).
1894e1a33b1SSven Schmidt * It also runs faster, so it's a recommended setting.
1904e1a33b1SSven Schmidt * If the function cannot compress 'source' into a more limited 'dest' budget,
1914e1a33b1SSven Schmidt * compression stops *immediately*, and the function result is zero.
1924e1a33b1SSven Schmidt * As a consequence, 'dest' content is not valid.
1934e1a33b1SSven Schmidt *
1944e1a33b1SSven Schmidt * Return: Number of bytes written into buffer 'dest'
1954e1a33b1SSven Schmidt * (necessarily <= maxOutputSize) or 0 if compression fails
1964e1a33b1SSven Schmidt */
1974e1a33b1SSven Schmidt int LZ4_compress_default(const char *source, char *dest, int inputSize,
1984e1a33b1SSven Schmidt int maxOutputSize, void *wrkmem);
1994e1a33b1SSven Schmidt
2004e1a33b1SSven Schmidt /**
2014e1a33b1SSven Schmidt * LZ4_compress_fast() - As LZ4_compress_default providing an acceleration param
2024e1a33b1SSven Schmidt * @source: source address of the original data
2034e1a33b1SSven Schmidt * @dest: output buffer address of the compressed data
2044e1a33b1SSven Schmidt * @inputSize: size of the input data. Max supported value is LZ4_MAX_INPUT_SIZE
2054e1a33b1SSven Schmidt * @maxOutputSize: full or partial size of buffer 'dest'
2064e1a33b1SSven Schmidt * which must be already allocated
2074e1a33b1SSven Schmidt * @acceleration: acceleration factor
2084e1a33b1SSven Schmidt * @wrkmem: address of the working memory.
2094e1a33b1SSven Schmidt * This requires 'workmem' of LZ4_MEM_COMPRESS.
2104e1a33b1SSven Schmidt *
2114e1a33b1SSven Schmidt * Same as LZ4_compress_default(), but allows to select an "acceleration"
2124e1a33b1SSven Schmidt * factor. The larger the acceleration value, the faster the algorithm,
2134e1a33b1SSven Schmidt * but also the lesser the compression. It's a trade-off. It can be fine tuned,
2144e1a33b1SSven Schmidt * with each successive value providing roughly +~3% to speed.
2154e1a33b1SSven Schmidt * An acceleration value of "1" is the same as regular LZ4_compress_default()
2164e1a33b1SSven Schmidt * Values <= 0 will be replaced by LZ4_ACCELERATION_DEFAULT, which is 1.
2174e1a33b1SSven Schmidt *
2184e1a33b1SSven Schmidt * Return: Number of bytes written into buffer 'dest'
2194e1a33b1SSven Schmidt * (necessarily <= maxOutputSize) or 0 if compression fails
2204e1a33b1SSven Schmidt */
2214e1a33b1SSven Schmidt int LZ4_compress_fast(const char *source, char *dest, int inputSize,
2224e1a33b1SSven Schmidt int maxOutputSize, int acceleration, void *wrkmem);
2234e1a33b1SSven Schmidt
2244e1a33b1SSven Schmidt /**
2254e1a33b1SSven Schmidt * LZ4_compress_destSize() - Compress as much data as possible
2264e1a33b1SSven Schmidt * from source to dest
2274e1a33b1SSven Schmidt * @source: source address of the original data
2284e1a33b1SSven Schmidt * @dest: output buffer address of the compressed data
2294e1a33b1SSven Schmidt * @sourceSizePtr: will be modified to indicate how many bytes where read
2304e1a33b1SSven Schmidt * from 'source' to fill 'dest'. New value is necessarily <= old value.
2314e1a33b1SSven Schmidt * @targetDestSize: Size of buffer 'dest' which must be already allocated
2324e1a33b1SSven Schmidt * @wrkmem: address of the working memory.
2334e1a33b1SSven Schmidt * This requires 'workmem' of LZ4_MEM_COMPRESS.
2344e1a33b1SSven Schmidt *
2354e1a33b1SSven Schmidt * Reverse the logic, by compressing as much data as possible
2364e1a33b1SSven Schmidt * from 'source' buffer into already allocated buffer 'dest'
2374e1a33b1SSven Schmidt * of size 'targetDestSize'.
2384e1a33b1SSven Schmidt * This function either compresses the entire 'source' content into 'dest'
2394e1a33b1SSven Schmidt * if it's large enough, or fill 'dest' buffer completely with as much data as
2404e1a33b1SSven Schmidt * possible from 'source'.
2414e1a33b1SSven Schmidt *
2424e1a33b1SSven Schmidt * Return: Number of bytes written into 'dest' (necessarily <= targetDestSize)
2434e1a33b1SSven Schmidt * or 0 if compression fails
2444e1a33b1SSven Schmidt */
2454e1a33b1SSven Schmidt int LZ4_compress_destSize(const char *source, char *dest, int *sourceSizePtr,
2464e1a33b1SSven Schmidt int targetDestSize, void *wrkmem);
247c72ac7a1SChanho Min
2484e1a33b1SSven Schmidt /*-************************************************************************
2494e1a33b1SSven Schmidt * Decompression Functions
2504e1a33b1SSven Schmidt **************************************************************************/
2514e1a33b1SSven Schmidt
2524e1a33b1SSven Schmidt /**
2534e1a33b1SSven Schmidt * LZ4_decompress_fast() - Decompresses data from 'source' into 'dest'
2544e1a33b1SSven Schmidt * @source: source address of the compressed data
2554e1a33b1SSven Schmidt * @dest: output buffer address of the uncompressed data
2564e1a33b1SSven Schmidt * which must be already allocated with 'originalSize' bytes
2574e1a33b1SSven Schmidt * @originalSize: is the original and therefore uncompressed size
2584e1a33b1SSven Schmidt *
2594e1a33b1SSven Schmidt * Decompresses data from 'source' into 'dest'.
2604e1a33b1SSven Schmidt * This function fully respect memory boundaries for properly formed
2614e1a33b1SSven Schmidt * compressed data.
2624e1a33b1SSven Schmidt * It is a bit faster than LZ4_decompress_safe().
2634e1a33b1SSven Schmidt * However, it does not provide any protection against intentionally
2644e1a33b1SSven Schmidt * modified data stream (malicious input).
2654e1a33b1SSven Schmidt * Use this function in trusted environment only
2664e1a33b1SSven Schmidt * (data to decode comes from a trusted source).
2674e1a33b1SSven Schmidt *
2684e1a33b1SSven Schmidt * Return: number of bytes read from the source buffer
2694e1a33b1SSven Schmidt * or a negative result if decompression fails.
2704e1a33b1SSven Schmidt */
2714e1a33b1SSven Schmidt int LZ4_decompress_fast(const char *source, char *dest, int originalSize);
2724e1a33b1SSven Schmidt
2734e1a33b1SSven Schmidt /**
2744e1a33b1SSven Schmidt * LZ4_decompress_safe() - Decompression protected against buffer overflow
2754e1a33b1SSven Schmidt * @source: source address of the compressed data
2764e1a33b1SSven Schmidt * @dest: output buffer address of the uncompressed data
2774e1a33b1SSven Schmidt * which must be already allocated
2784e1a33b1SSven Schmidt * @compressedSize: is the precise full size of the compressed block
2794e1a33b1SSven Schmidt * @maxDecompressedSize: is the size of 'dest' buffer
2804e1a33b1SSven Schmidt *
28197a0efeaSTom Levy * Decompresses data from 'source' into 'dest'.
2824e1a33b1SSven Schmidt * If the source stream is detected malformed, the function will
2834e1a33b1SSven Schmidt * stop decoding and return a negative result.
2844e1a33b1SSven Schmidt * This function is protected against buffer overflow exploits,
2854e1a33b1SSven Schmidt * including malicious data packets. It never writes outside output buffer,
2864e1a33b1SSven Schmidt * nor reads outside input buffer.
2874e1a33b1SSven Schmidt *
2884e1a33b1SSven Schmidt * Return: number of bytes decompressed into destination buffer
2894e1a33b1SSven Schmidt * (necessarily <= maxDecompressedSize)
2904e1a33b1SSven Schmidt * or a negative result in case of error
2914e1a33b1SSven Schmidt */
2924e1a33b1SSven Schmidt int LZ4_decompress_safe(const char *source, char *dest, int compressedSize,
2934e1a33b1SSven Schmidt int maxDecompressedSize);
2944e1a33b1SSven Schmidt
2954e1a33b1SSven Schmidt /**
2964e1a33b1SSven Schmidt * LZ4_decompress_safe_partial() - Decompress a block of size 'compressedSize'
2974e1a33b1SSven Schmidt * at position 'source' into buffer 'dest'
2984e1a33b1SSven Schmidt * @source: source address of the compressed data
2994e1a33b1SSven Schmidt * @dest: output buffer address of the decompressed data which must be
3004e1a33b1SSven Schmidt * already allocated
3014e1a33b1SSven Schmidt * @compressedSize: is the precise full size of the compressed block.
3024e1a33b1SSven Schmidt * @targetOutputSize: the decompression operation will try
3034e1a33b1SSven Schmidt * to stop as soon as 'targetOutputSize' has been reached
3044e1a33b1SSven Schmidt * @maxDecompressedSize: is the size of destination buffer
3054e1a33b1SSven Schmidt *
3064e1a33b1SSven Schmidt * This function decompresses a compressed block of size 'compressedSize'
3074e1a33b1SSven Schmidt * at position 'source' into destination buffer 'dest'
3084e1a33b1SSven Schmidt * of size 'maxDecompressedSize'.
3094e1a33b1SSven Schmidt * The function tries to stop decompressing operation as soon as
3104e1a33b1SSven Schmidt * 'targetOutputSize' has been reached, reducing decompression time.
3114e1a33b1SSven Schmidt * This function never writes outside of output buffer,
3124e1a33b1SSven Schmidt * and never reads outside of input buffer.
3134e1a33b1SSven Schmidt * It is therefore protected against malicious data packets.
3144e1a33b1SSven Schmidt *
3154e1a33b1SSven Schmidt * Return: the number of bytes decoded in the destination buffer
3164e1a33b1SSven Schmidt * (necessarily <= maxDecompressedSize)
3174e1a33b1SSven Schmidt * or a negative result in case of error
3184e1a33b1SSven Schmidt *
3194e1a33b1SSven Schmidt */
3204e1a33b1SSven Schmidt int LZ4_decompress_safe_partial(const char *source, char *dest,
3214e1a33b1SSven Schmidt int compressedSize, int targetOutputSize, int maxDecompressedSize);
322c72ac7a1SChanho Min
3234e1a33b1SSven Schmidt /*-************************************************************************
3244e1a33b1SSven Schmidt * LZ4 HC Compression
3254e1a33b1SSven Schmidt **************************************************************************/
3264e1a33b1SSven Schmidt
3274e1a33b1SSven Schmidt /**
3284e1a33b1SSven Schmidt * LZ4_compress_HC() - Compress data from `src` into `dst`, using HC algorithm
3294e1a33b1SSven Schmidt * @src: source address of the original data
3304e1a33b1SSven Schmidt * @dst: output buffer address of the compressed data
3314e1a33b1SSven Schmidt * @srcSize: size of the input data. Max supported value is LZ4_MAX_INPUT_SIZE
3324e1a33b1SSven Schmidt * @dstCapacity: full or partial size of buffer 'dst',
3334e1a33b1SSven Schmidt * which must be already allocated
3344e1a33b1SSven Schmidt * @compressionLevel: Recommended values are between 4 and 9, although any
3354e1a33b1SSven Schmidt * value between 1 and LZ4HC_MAX_CLEVEL will work.
3364e1a33b1SSven Schmidt * Values >LZ4HC_MAX_CLEVEL behave the same as 16.
3374e1a33b1SSven Schmidt * @wrkmem: address of the working memory.
3384e1a33b1SSven Schmidt * This requires 'wrkmem' of size LZ4HC_MEM_COMPRESS.
3394e1a33b1SSven Schmidt *
3404e1a33b1SSven Schmidt * Compress data from 'src' into 'dst', using the more powerful
3414e1a33b1SSven Schmidt * but slower "HC" algorithm. Compression is guaranteed to succeed if
3424e1a33b1SSven Schmidt * `dstCapacity >= LZ4_compressBound(srcSize)
3434e1a33b1SSven Schmidt *
3444e1a33b1SSven Schmidt * Return : the number of bytes written into 'dst' or 0 if compression fails.
345cffb78b0SKyungsik Lee */
3464e1a33b1SSven Schmidt int LZ4_compress_HC(const char *src, char *dst, int srcSize, int dstCapacity,
3474e1a33b1SSven Schmidt int compressionLevel, void *wrkmem);
3484e1a33b1SSven Schmidt
3494e1a33b1SSven Schmidt /**
3504e1a33b1SSven Schmidt * LZ4_resetStreamHC() - Init an allocated 'LZ4_streamHC_t' structure
3514e1a33b1SSven Schmidt * @streamHCPtr: pointer to the 'LZ4_streamHC_t' structure
3524e1a33b1SSven Schmidt * @compressionLevel: Recommended values are between 4 and 9, although any
3534e1a33b1SSven Schmidt * value between 1 and LZ4HC_MAX_CLEVEL will work.
3544e1a33b1SSven Schmidt * Values >LZ4HC_MAX_CLEVEL behave the same as 16.
3554e1a33b1SSven Schmidt *
3564e1a33b1SSven Schmidt * An LZ4_streamHC_t structure can be allocated once
3574e1a33b1SSven Schmidt * and re-used multiple times.
3584e1a33b1SSven Schmidt * Use this function to init an allocated `LZ4_streamHC_t` structure
3594e1a33b1SSven Schmidt * and start a new compression.
3604e1a33b1SSven Schmidt */
3614e1a33b1SSven Schmidt void LZ4_resetStreamHC(LZ4_streamHC_t *streamHCPtr, int compressionLevel);
3624e1a33b1SSven Schmidt
3634e1a33b1SSven Schmidt /**
3644e1a33b1SSven Schmidt * LZ4_loadDictHC() - Load a static dictionary into LZ4_streamHC
3654e1a33b1SSven Schmidt * @streamHCPtr: pointer to the LZ4HC_stream_t
3664e1a33b1SSven Schmidt * @dictionary: dictionary to load
3674e1a33b1SSven Schmidt * @dictSize: size of dictionary
3684e1a33b1SSven Schmidt *
3694e1a33b1SSven Schmidt * Use this function to load a static dictionary into LZ4HC_stream.
3704e1a33b1SSven Schmidt * Any previous data will be forgotten, only 'dictionary'
3714e1a33b1SSven Schmidt * will remain in memory.
3724e1a33b1SSven Schmidt * Loading a size of 0 is allowed.
3734e1a33b1SSven Schmidt *
3744e1a33b1SSven Schmidt * Return : dictionary size, in bytes (necessarily <= 64 KB)
3754e1a33b1SSven Schmidt */
3764e1a33b1SSven Schmidt int LZ4_loadDictHC(LZ4_streamHC_t *streamHCPtr, const char *dictionary,
3774e1a33b1SSven Schmidt int dictSize);
3784e1a33b1SSven Schmidt
3794e1a33b1SSven Schmidt /**
3804e1a33b1SSven Schmidt * LZ4_compress_HC_continue() - Compress 'src' using data from previously
3814e1a33b1SSven Schmidt * compressed blocks as a dictionary using the HC algorithm
3824e1a33b1SSven Schmidt * @streamHCPtr: Pointer to the previous 'LZ4_streamHC_t' structure
3834e1a33b1SSven Schmidt * @src: source address of the original data
3844e1a33b1SSven Schmidt * @dst: output buffer address of the compressed data,
3854e1a33b1SSven Schmidt * which must be already allocated
3864e1a33b1SSven Schmidt * @srcSize: size of the input data. Max supported value is LZ4_MAX_INPUT_SIZE
3874e1a33b1SSven Schmidt * @maxDstSize: full or partial size of buffer 'dest'
3884e1a33b1SSven Schmidt * which must be already allocated
3894e1a33b1SSven Schmidt *
3904e1a33b1SSven Schmidt * These functions compress data in successive blocks of any size, using
3914e1a33b1SSven Schmidt * previous blocks as dictionary. One key assumption is that previous
3924e1a33b1SSven Schmidt * blocks (up to 64 KB) remain read-accessible while
3934e1a33b1SSven Schmidt * compressing next blocks. There is an exception for ring buffers,
3944e1a33b1SSven Schmidt * which can be smaller than 64 KB.
3954e1a33b1SSven Schmidt * Ring buffers scenario is automatically detected and handled by
3964e1a33b1SSven Schmidt * LZ4_compress_HC_continue().
3974e1a33b1SSven Schmidt * Before starting compression, state must be properly initialized,
3984e1a33b1SSven Schmidt * using LZ4_resetStreamHC().
3994e1a33b1SSven Schmidt * A first "fictional block" can then be designated as
4004e1a33b1SSven Schmidt * initial dictionary, using LZ4_loadDictHC() (Optional).
4014e1a33b1SSven Schmidt * Then, use LZ4_compress_HC_continue()
4024e1a33b1SSven Schmidt * to compress each successive block. Previous memory blocks
4034e1a33b1SSven Schmidt * (including initial dictionary when present) must remain accessible
4044e1a33b1SSven Schmidt * and unmodified during compression.
4054e1a33b1SSven Schmidt * 'dst' buffer should be sized to handle worst case scenarios, using
4064e1a33b1SSven Schmidt * LZ4_compressBound(), to ensure operation success.
4074e1a33b1SSven Schmidt * If, for any reason, previous data blocks can't be preserved unmodified
4084e1a33b1SSven Schmidt * in memory during next compression block,
4094e1a33b1SSven Schmidt * you must save it to a safer memory space, using LZ4_saveDictHC().
4104e1a33b1SSven Schmidt * Return value of LZ4_saveDictHC() is the size of dictionary
4114e1a33b1SSven Schmidt * effectively saved into 'safeBuffer'.
4124e1a33b1SSven Schmidt *
4134e1a33b1SSven Schmidt * Return: Number of bytes written into buffer 'dst' or 0 if compression fails
4144e1a33b1SSven Schmidt */
4154e1a33b1SSven Schmidt int LZ4_compress_HC_continue(LZ4_streamHC_t *streamHCPtr, const char *src,
4164e1a33b1SSven Schmidt char *dst, int srcSize, int maxDstSize);
4174e1a33b1SSven Schmidt
4184e1a33b1SSven Schmidt /**
4194e1a33b1SSven Schmidt * LZ4_saveDictHC() - Save static dictionary from LZ4HC_stream
4204e1a33b1SSven Schmidt * @streamHCPtr: pointer to the 'LZ4HC_stream_t' structure
4214e1a33b1SSven Schmidt * @safeBuffer: buffer to save dictionary to, must be already allocated
4224e1a33b1SSven Schmidt * @maxDictSize: size of 'safeBuffer'
4234e1a33b1SSven Schmidt *
4244e1a33b1SSven Schmidt * If previously compressed data block is not guaranteed
4254e1a33b1SSven Schmidt * to remain available at its memory location,
4264e1a33b1SSven Schmidt * save it into a safer place (char *safeBuffer).
4274e1a33b1SSven Schmidt * Note : you don't need to call LZ4_loadDictHC() afterwards,
4284e1a33b1SSven Schmidt * dictionary is immediately usable, you can therefore call
4294e1a33b1SSven Schmidt * LZ4_compress_HC_continue().
4304e1a33b1SSven Schmidt *
4314e1a33b1SSven Schmidt * Return : saved dictionary size in bytes (necessarily <= maxDictSize),
4324e1a33b1SSven Schmidt * or 0 if error.
4334e1a33b1SSven Schmidt */
4344e1a33b1SSven Schmidt int LZ4_saveDictHC(LZ4_streamHC_t *streamHCPtr, char *safeBuffer,
4354e1a33b1SSven Schmidt int maxDictSize);
4364e1a33b1SSven Schmidt
4374e1a33b1SSven Schmidt /*-*********************************************
4384e1a33b1SSven Schmidt * Streaming Compression Functions
4394e1a33b1SSven Schmidt ***********************************************/
4404e1a33b1SSven Schmidt
4414e1a33b1SSven Schmidt /**
4424e1a33b1SSven Schmidt * LZ4_resetStream() - Init an allocated 'LZ4_stream_t' structure
4434e1a33b1SSven Schmidt * @LZ4_stream: pointer to the 'LZ4_stream_t' structure
4444e1a33b1SSven Schmidt *
4454e1a33b1SSven Schmidt * An LZ4_stream_t structure can be allocated once
4464e1a33b1SSven Schmidt * and re-used multiple times.
4474e1a33b1SSven Schmidt * Use this function to init an allocated `LZ4_stream_t` structure
4484e1a33b1SSven Schmidt * and start a new compression.
4494e1a33b1SSven Schmidt */
4504e1a33b1SSven Schmidt void LZ4_resetStream(LZ4_stream_t *LZ4_stream);
4514e1a33b1SSven Schmidt
4524e1a33b1SSven Schmidt /**
4534e1a33b1SSven Schmidt * LZ4_loadDict() - Load a static dictionary into LZ4_stream
4544e1a33b1SSven Schmidt * @streamPtr: pointer to the LZ4_stream_t
4554e1a33b1SSven Schmidt * @dictionary: dictionary to load
4564e1a33b1SSven Schmidt * @dictSize: size of dictionary
4574e1a33b1SSven Schmidt *
4584e1a33b1SSven Schmidt * Use this function to load a static dictionary into LZ4_stream.
4594e1a33b1SSven Schmidt * Any previous data will be forgotten, only 'dictionary'
4604e1a33b1SSven Schmidt * will remain in memory.
4614e1a33b1SSven Schmidt * Loading a size of 0 is allowed.
4624e1a33b1SSven Schmidt *
4634e1a33b1SSven Schmidt * Return : dictionary size, in bytes (necessarily <= 64 KB)
4644e1a33b1SSven Schmidt */
4654e1a33b1SSven Schmidt int LZ4_loadDict(LZ4_stream_t *streamPtr, const char *dictionary,
4664e1a33b1SSven Schmidt int dictSize);
4674e1a33b1SSven Schmidt
4684e1a33b1SSven Schmidt /**
4694e1a33b1SSven Schmidt * LZ4_saveDict() - Save static dictionary from LZ4_stream
4704e1a33b1SSven Schmidt * @streamPtr: pointer to the 'LZ4_stream_t' structure
4714e1a33b1SSven Schmidt * @safeBuffer: buffer to save dictionary to, must be already allocated
4724e1a33b1SSven Schmidt * @dictSize: size of 'safeBuffer'
4734e1a33b1SSven Schmidt *
4744e1a33b1SSven Schmidt * If previously compressed data block is not guaranteed
4754e1a33b1SSven Schmidt * to remain available at its memory location,
4764e1a33b1SSven Schmidt * save it into a safer place (char *safeBuffer).
4774e1a33b1SSven Schmidt * Note : you don't need to call LZ4_loadDict() afterwards,
4784e1a33b1SSven Schmidt * dictionary is immediately usable, you can therefore call
4794e1a33b1SSven Schmidt * LZ4_compress_fast_continue().
4804e1a33b1SSven Schmidt *
4814e1a33b1SSven Schmidt * Return : saved dictionary size in bytes (necessarily <= dictSize),
4824e1a33b1SSven Schmidt * or 0 if error.
4834e1a33b1SSven Schmidt */
4844e1a33b1SSven Schmidt int LZ4_saveDict(LZ4_stream_t *streamPtr, char *safeBuffer, int dictSize);
4854e1a33b1SSven Schmidt
4864e1a33b1SSven Schmidt /**
4874e1a33b1SSven Schmidt * LZ4_compress_fast_continue() - Compress 'src' using data from previously
4884e1a33b1SSven Schmidt * compressed blocks as a dictionary
4894e1a33b1SSven Schmidt * @streamPtr: Pointer to the previous 'LZ4_stream_t' structure
4904e1a33b1SSven Schmidt * @src: source address of the original data
4914e1a33b1SSven Schmidt * @dst: output buffer address of the compressed data,
4924e1a33b1SSven Schmidt * which must be already allocated
4934e1a33b1SSven Schmidt * @srcSize: size of the input data. Max supported value is LZ4_MAX_INPUT_SIZE
4944e1a33b1SSven Schmidt * @maxDstSize: full or partial size of buffer 'dest'
4954e1a33b1SSven Schmidt * which must be already allocated
4964e1a33b1SSven Schmidt * @acceleration: acceleration factor
4974e1a33b1SSven Schmidt *
4984e1a33b1SSven Schmidt * Compress buffer content 'src', using data from previously compressed blocks
4994e1a33b1SSven Schmidt * as dictionary to improve compression ratio.
5004e1a33b1SSven Schmidt * Important : Previous data blocks are assumed to still
5014e1a33b1SSven Schmidt * be present and unmodified !
5024e1a33b1SSven Schmidt * If maxDstSize >= LZ4_compressBound(srcSize),
5034e1a33b1SSven Schmidt * compression is guaranteed to succeed, and runs faster.
5044e1a33b1SSven Schmidt *
5054e1a33b1SSven Schmidt * Return: Number of bytes written into buffer 'dst' or 0 if compression fails
5064e1a33b1SSven Schmidt */
5074e1a33b1SSven Schmidt int LZ4_compress_fast_continue(LZ4_stream_t *streamPtr, const char *src,
5084e1a33b1SSven Schmidt char *dst, int srcSize, int maxDstSize, int acceleration);
5094e1a33b1SSven Schmidt
5104e1a33b1SSven Schmidt /**
5114e1a33b1SSven Schmidt * LZ4_setStreamDecode() - Instruct where to find dictionary
5124e1a33b1SSven Schmidt * @LZ4_streamDecode: the 'LZ4_streamDecode_t' structure
5134e1a33b1SSven Schmidt * @dictionary: dictionary to use
5144e1a33b1SSven Schmidt * @dictSize: size of dictionary
5154e1a33b1SSven Schmidt *
5164e1a33b1SSven Schmidt * Use this function to instruct where to find the dictionary.
5174e1a33b1SSven Schmidt * Setting a size of 0 is allowed (same effect as reset).
5184e1a33b1SSven Schmidt *
5194e1a33b1SSven Schmidt * Return: 1 if OK, 0 if error
5204e1a33b1SSven Schmidt */
5214e1a33b1SSven Schmidt int LZ4_setStreamDecode(LZ4_streamDecode_t *LZ4_streamDecode,
5224e1a33b1SSven Schmidt const char *dictionary, int dictSize);
5234e1a33b1SSven Schmidt
5244e1a33b1SSven Schmidt /**
52597a0efeaSTom Levy * LZ4_decompress_safe_continue() - Decompress blocks in streaming mode
5264e1a33b1SSven Schmidt * @LZ4_streamDecode: the 'LZ4_streamDecode_t' structure
5274e1a33b1SSven Schmidt * @source: source address of the compressed data
5284e1a33b1SSven Schmidt * @dest: output buffer address of the uncompressed data
5294e1a33b1SSven Schmidt * which must be already allocated
5304e1a33b1SSven Schmidt * @compressedSize: is the precise full size of the compressed block
5314e1a33b1SSven Schmidt * @maxDecompressedSize: is the size of 'dest' buffer
5324e1a33b1SSven Schmidt *
53397a0efeaSTom Levy * This decoding function allows decompression of multiple blocks
5344e1a33b1SSven Schmidt * in "streaming" mode.
5354e1a33b1SSven Schmidt * Previously decoded blocks *must* remain available at the memory position
5364e1a33b1SSven Schmidt * where they were decoded (up to 64 KB)
5374e1a33b1SSven Schmidt * In the case of a ring buffers, decoding buffer must be either :
5384e1a33b1SSven Schmidt * - Exactly same size as encoding buffer, with same update rule
5394e1a33b1SSven Schmidt * (block boundaries at same positions) In which case,
5404e1a33b1SSven Schmidt * the decoding & encoding ring buffer can have any size,
5414e1a33b1SSven Schmidt * including very small ones ( < 64 KB).
5424e1a33b1SSven Schmidt * - Larger than encoding buffer, by a minimum of maxBlockSize more bytes.
5434e1a33b1SSven Schmidt * maxBlockSize is implementation dependent.
5444e1a33b1SSven Schmidt * It's the maximum size you intend to compress into a single block.
5454e1a33b1SSven Schmidt * In which case, encoding and decoding buffers do not need
5464e1a33b1SSven Schmidt * to be synchronized, and encoding ring buffer can have any size,
5474e1a33b1SSven Schmidt * including small ones ( < 64 KB).
5484e1a33b1SSven Schmidt * - _At least_ 64 KB + 8 bytes + maxBlockSize.
5494e1a33b1SSven Schmidt * In which case, encoding and decoding buffers do not need to be
5504e1a33b1SSven Schmidt * synchronized, and encoding ring buffer can have any size,
5514e1a33b1SSven Schmidt * including larger than decoding buffer. W
5524e1a33b1SSven Schmidt * Whenever these conditions are not possible, save the last 64KB of decoded
5534e1a33b1SSven Schmidt * data into a safe buffer, and indicate where it is saved
5544e1a33b1SSven Schmidt * using LZ4_setStreamDecode()
5554e1a33b1SSven Schmidt *
5564e1a33b1SSven Schmidt * Return: number of bytes decompressed into destination buffer
5574e1a33b1SSven Schmidt * (necessarily <= maxDecompressedSize)
5584e1a33b1SSven Schmidt * or a negative result in case of error
5594e1a33b1SSven Schmidt */
5604e1a33b1SSven Schmidt int LZ4_decompress_safe_continue(LZ4_streamDecode_t *LZ4_streamDecode,
5614e1a33b1SSven Schmidt const char *source, char *dest, int compressedSize,
5624e1a33b1SSven Schmidt int maxDecompressedSize);
5634e1a33b1SSven Schmidt
5644e1a33b1SSven Schmidt /**
5654e1a33b1SSven Schmidt * LZ4_decompress_fast_continue() - Decompress blocks in streaming mode
5664e1a33b1SSven Schmidt * @LZ4_streamDecode: the 'LZ4_streamDecode_t' structure
5674e1a33b1SSven Schmidt * @source: source address of the compressed data
5684e1a33b1SSven Schmidt * @dest: output buffer address of the uncompressed data
5694e1a33b1SSven Schmidt * which must be already allocated with 'originalSize' bytes
5704e1a33b1SSven Schmidt * @originalSize: is the original and therefore uncompressed size
5714e1a33b1SSven Schmidt *
57297a0efeaSTom Levy * This decoding function allows decompression of multiple blocks
5734e1a33b1SSven Schmidt * in "streaming" mode.
5744e1a33b1SSven Schmidt * Previously decoded blocks *must* remain available at the memory position
5754e1a33b1SSven Schmidt * where they were decoded (up to 64 KB)
5764e1a33b1SSven Schmidt * In the case of a ring buffers, decoding buffer must be either :
5774e1a33b1SSven Schmidt * - Exactly same size as encoding buffer, with same update rule
5784e1a33b1SSven Schmidt * (block boundaries at same positions) In which case,
5794e1a33b1SSven Schmidt * the decoding & encoding ring buffer can have any size,
5804e1a33b1SSven Schmidt * including very small ones ( < 64 KB).
5814e1a33b1SSven Schmidt * - Larger than encoding buffer, by a minimum of maxBlockSize more bytes.
5824e1a33b1SSven Schmidt * maxBlockSize is implementation dependent.
5834e1a33b1SSven Schmidt * It's the maximum size you intend to compress into a single block.
5844e1a33b1SSven Schmidt * In which case, encoding and decoding buffers do not need
5854e1a33b1SSven Schmidt * to be synchronized, and encoding ring buffer can have any size,
5864e1a33b1SSven Schmidt * including small ones ( < 64 KB).
5874e1a33b1SSven Schmidt * - _At least_ 64 KB + 8 bytes + maxBlockSize.
5884e1a33b1SSven Schmidt * In which case, encoding and decoding buffers do not need to be
5894e1a33b1SSven Schmidt * synchronized, and encoding ring buffer can have any size,
5904e1a33b1SSven Schmidt * including larger than decoding buffer. W
5914e1a33b1SSven Schmidt * Whenever these conditions are not possible, save the last 64KB of decoded
5924e1a33b1SSven Schmidt * data into a safe buffer, and indicate where it is saved
5934e1a33b1SSven Schmidt * using LZ4_setStreamDecode()
5944e1a33b1SSven Schmidt *
5954e1a33b1SSven Schmidt * Return: number of bytes decompressed into destination buffer
5964e1a33b1SSven Schmidt * (necessarily <= maxDecompressedSize)
5974e1a33b1SSven Schmidt * or a negative result in case of error
5984e1a33b1SSven Schmidt */
5994e1a33b1SSven Schmidt int LZ4_decompress_fast_continue(LZ4_streamDecode_t *LZ4_streamDecode,
6004e1a33b1SSven Schmidt const char *source, char *dest, int originalSize);
6014e1a33b1SSven Schmidt
6024e1a33b1SSven Schmidt /**
6034e1a33b1SSven Schmidt * LZ4_decompress_safe_usingDict() - Same as LZ4_setStreamDecode()
6044e1a33b1SSven Schmidt * followed by LZ4_decompress_safe_continue()
6054e1a33b1SSven Schmidt * @source: source address of the compressed data
6064e1a33b1SSven Schmidt * @dest: output buffer address of the uncompressed data
6074e1a33b1SSven Schmidt * which must be already allocated
6084e1a33b1SSven Schmidt * @compressedSize: is the precise full size of the compressed block
6094e1a33b1SSven Schmidt * @maxDecompressedSize: is the size of 'dest' buffer
6104e1a33b1SSven Schmidt * @dictStart: pointer to the start of the dictionary in memory
6114e1a33b1SSven Schmidt * @dictSize: size of dictionary
6124e1a33b1SSven Schmidt *
61397a0efeaSTom Levy * This decoding function works the same as
6144e1a33b1SSven Schmidt * a combination of LZ4_setStreamDecode() followed by
6154e1a33b1SSven Schmidt * LZ4_decompress_safe_continue()
61697a0efeaSTom Levy * It is stand-alone, and doesn't need an LZ4_streamDecode_t structure.
6174e1a33b1SSven Schmidt *
6184e1a33b1SSven Schmidt * Return: number of bytes decompressed into destination buffer
6194e1a33b1SSven Schmidt * (necessarily <= maxDecompressedSize)
6204e1a33b1SSven Schmidt * or a negative result in case of error
6214e1a33b1SSven Schmidt */
6224e1a33b1SSven Schmidt int LZ4_decompress_safe_usingDict(const char *source, char *dest,
6234e1a33b1SSven Schmidt int compressedSize, int maxDecompressedSize, const char *dictStart,
6244e1a33b1SSven Schmidt int dictSize);
6254e1a33b1SSven Schmidt
6264e1a33b1SSven Schmidt /**
6274e1a33b1SSven Schmidt * LZ4_decompress_fast_usingDict() - Same as LZ4_setStreamDecode()
6284e1a33b1SSven Schmidt * followed by LZ4_decompress_fast_continue()
6294e1a33b1SSven Schmidt * @source: source address of the compressed data
6304e1a33b1SSven Schmidt * @dest: output buffer address of the uncompressed data
6314e1a33b1SSven Schmidt * which must be already allocated with 'originalSize' bytes
6324e1a33b1SSven Schmidt * @originalSize: is the original and therefore uncompressed size
6334e1a33b1SSven Schmidt * @dictStart: pointer to the start of the dictionary in memory
6344e1a33b1SSven Schmidt * @dictSize: size of dictionary
6354e1a33b1SSven Schmidt *
63697a0efeaSTom Levy * This decoding function works the same as
6374e1a33b1SSven Schmidt * a combination of LZ4_setStreamDecode() followed by
63897a0efeaSTom Levy * LZ4_decompress_fast_continue()
63997a0efeaSTom Levy * It is stand-alone, and doesn't need an LZ4_streamDecode_t structure.
6404e1a33b1SSven Schmidt *
6414e1a33b1SSven Schmidt * Return: number of bytes decompressed into destination buffer
6424e1a33b1SSven Schmidt * (necessarily <= maxDecompressedSize)
6434e1a33b1SSven Schmidt * or a negative result in case of error
6444e1a33b1SSven Schmidt */
6454e1a33b1SSven Schmidt int LZ4_decompress_fast_usingDict(const char *source, char *dest,
6464e1a33b1SSven Schmidt int originalSize, const char *dictStart, int dictSize);
6474e1a33b1SSven Schmidt
648*f0ef073eSGao Xiang #define LZ4_DECOMPRESS_INPLACE_MARGIN(compressedSize) (((compressedSize) >> 8) + 32)
649*f0ef073eSGao Xiang
650*f0ef073eSGao Xiang #ifndef LZ4_DISTANCE_MAX /* history window size; can be user-defined at compile time */
651*f0ef073eSGao Xiang #define LZ4_DISTANCE_MAX 65535 /* set to maximum value by default */
652*f0ef073eSGao Xiang #endif
653*f0ef073eSGao Xiang
654cffb78b0SKyungsik Lee #endif
655