![]() |
|
|||
0001 /* LZ4 Kernel Interface 0002 * 0003 * Copyright (C) 2013, LG Electronics, Kyungsik Lee <kyungsik.lee@lge.com> 0004 * Copyright (C) 2016, Sven Schmidt <4sschmid@informatik.uni-hamburg.de> 0005 * 0006 * This program is free software; you can redistribute it and/or modify 0007 * it under the terms of the GNU General Public License version 2 as 0008 * published by the Free Software Foundation. 0009 * 0010 * This file is based on the original header file 0011 * for LZ4 - Fast LZ compression algorithm. 0012 * 0013 * LZ4 - Fast LZ compression algorithm 0014 * Copyright (C) 2011-2016, Yann Collet. 0015 * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) 0016 * Redistribution and use in source and binary forms, with or without 0017 * modification, are permitted provided that the following conditions are 0018 * met: 0019 * * Redistributions of source code must retain the above copyright 0020 * notice, this list of conditions and the following disclaimer. 0021 * * Redistributions in binary form must reproduce the above 0022 * copyright notice, this list of conditions and the following disclaimer 0023 * in the documentation and/or other materials provided with the 0024 * distribution. 0025 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 0026 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 0027 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 0028 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 0029 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 0030 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 0031 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0032 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0033 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0034 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0035 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0036 * You can contact the author at : 0037 * - LZ4 homepage : http://www.lz4.org 0038 * - LZ4 source repository : https://github.com/lz4/lz4 0039 */ 0040 0041 #ifndef __LZ4_H__ 0042 #define __LZ4_H__ 0043 0044 #include <linux/types.h> 0045 #include <linux/string.h> /* memset, memcpy */ 0046 0047 /*-************************************************************************ 0048 * CONSTANTS 0049 **************************************************************************/ 0050 /* 0051 * LZ4_MEMORY_USAGE : 0052 * Memory usage formula : N->2^N Bytes 0053 * (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; etc.) 0054 * Increasing memory usage improves compression ratio 0055 * Reduced memory usage can improve speed, due to cache effect 0056 * Default value is 14, for 16KB, which nicely fits into Intel x86 L1 cache 0057 */ 0058 #define LZ4_MEMORY_USAGE 14 0059 0060 #define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */ 0061 #define LZ4_COMPRESSBOUND(isize) (\ 0062 (unsigned int)(isize) > (unsigned int)LZ4_MAX_INPUT_SIZE \ 0063 ? 0 \ 0064 : (isize) + ((isize)/255) + 16) 0065 0066 #define LZ4_ACCELERATION_DEFAULT 1 0067 #define LZ4_HASHLOG (LZ4_MEMORY_USAGE-2) 0068 #define LZ4_HASHTABLESIZE (1 << LZ4_MEMORY_USAGE) 0069 #define LZ4_HASH_SIZE_U32 (1 << LZ4_HASHLOG) 0070 0071 #define LZ4HC_MIN_CLEVEL 3 0072 #define LZ4HC_DEFAULT_CLEVEL 9 0073 #define LZ4HC_MAX_CLEVEL 16 0074 0075 #define LZ4HC_DICTIONARY_LOGSIZE 16 0076 #define LZ4HC_MAXD (1<<LZ4HC_DICTIONARY_LOGSIZE) 0077 #define LZ4HC_MAXD_MASK (LZ4HC_MAXD - 1) 0078 #define LZ4HC_HASH_LOG (LZ4HC_DICTIONARY_LOGSIZE - 1) 0079 #define LZ4HC_HASHTABLESIZE (1 << LZ4HC_HASH_LOG) 0080 #define LZ4HC_HASH_MASK (LZ4HC_HASHTABLESIZE - 1) 0081 0082 /*-************************************************************************ 0083 * STREAMING CONSTANTS AND STRUCTURES 0084 **************************************************************************/ 0085 #define LZ4_STREAMSIZE_U64 ((1 << (LZ4_MEMORY_USAGE - 3)) + 4) 0086 #define LZ4_STREAMSIZE (LZ4_STREAMSIZE_U64 * sizeof(unsigned long long)) 0087 0088 #define LZ4_STREAMHCSIZE 262192 0089 #define LZ4_STREAMHCSIZE_SIZET (262192 / sizeof(size_t)) 0090 0091 #define LZ4_STREAMDECODESIZE_U64 4 0092 #define LZ4_STREAMDECODESIZE (LZ4_STREAMDECODESIZE_U64 * \ 0093 sizeof(unsigned long long)) 0094 0095 /* 0096 * LZ4_stream_t - information structure to track an LZ4 stream. 0097 */ 0098 typedef struct { 0099 uint32_t hashTable[LZ4_HASH_SIZE_U32]; 0100 uint32_t currentOffset; 0101 uint32_t initCheck; 0102 const uint8_t *dictionary; 0103 uint8_t *bufferStart; 0104 uint32_t dictSize; 0105 } LZ4_stream_t_internal; 0106 typedef union { 0107 unsigned long long table[LZ4_STREAMSIZE_U64]; 0108 LZ4_stream_t_internal internal_donotuse; 0109 } LZ4_stream_t; 0110 0111 /* 0112 * LZ4_streamHC_t - information structure to track an LZ4HC stream. 0113 */ 0114 typedef struct { 0115 unsigned int hashTable[LZ4HC_HASHTABLESIZE]; 0116 unsigned short chainTable[LZ4HC_MAXD]; 0117 /* next block to continue on current prefix */ 0118 const unsigned char *end; 0119 /* All index relative to this position */ 0120 const unsigned char *base; 0121 /* alternate base for extDict */ 0122 const unsigned char *dictBase; 0123 /* below that point, need extDict */ 0124 unsigned int dictLimit; 0125 /* below that point, no more dict */ 0126 unsigned int lowLimit; 0127 /* index from which to continue dict update */ 0128 unsigned int nextToUpdate; 0129 unsigned int compressionLevel; 0130 } LZ4HC_CCtx_internal; 0131 typedef union { 0132 size_t table[LZ4_STREAMHCSIZE_SIZET]; 0133 LZ4HC_CCtx_internal internal_donotuse; 0134 } LZ4_streamHC_t; 0135 0136 /* 0137 * LZ4_streamDecode_t - information structure to track an 0138 * LZ4 stream during decompression. 0139 * 0140 * init this structure using LZ4_setStreamDecode (or memset()) before first use 0141 */ 0142 typedef struct { 0143 const uint8_t *externalDict; 0144 size_t extDictSize; 0145 const uint8_t *prefixEnd; 0146 size_t prefixSize; 0147 } LZ4_streamDecode_t_internal; 0148 typedef union { 0149 unsigned long long table[LZ4_STREAMDECODESIZE_U64]; 0150 LZ4_streamDecode_t_internal internal_donotuse; 0151 } LZ4_streamDecode_t; 0152 0153 /*-************************************************************************ 0154 * SIZE OF STATE 0155 **************************************************************************/ 0156 #define LZ4_MEM_COMPRESS LZ4_STREAMSIZE 0157 #define LZ4HC_MEM_COMPRESS LZ4_STREAMHCSIZE 0158 0159 /*-************************************************************************ 0160 * Compression Functions 0161 **************************************************************************/ 0162 0163 /** 0164 * LZ4_compressBound() - Max. output size in worst case szenarios 0165 * @isize: Size of the input data 0166 * 0167 * Return: Max. size LZ4 may output in a "worst case" szenario 0168 * (data not compressible) 0169 */ 0170 static inline int LZ4_compressBound(size_t isize) 0171 { 0172 return LZ4_COMPRESSBOUND(isize); 0173 } 0174 0175 /** 0176 * LZ4_compress_default() - Compress data from source to dest 0177 * @source: source address of the original data 0178 * @dest: output buffer address of the compressed data 0179 * @inputSize: size of the input data. Max supported value is LZ4_MAX_INPUT_SIZE 0180 * @maxOutputSize: full or partial size of buffer 'dest' 0181 * which must be already allocated 0182 * @wrkmem: address of the working memory. 0183 * This requires 'workmem' of LZ4_MEM_COMPRESS. 0184 * 0185 * Compresses 'sourceSize' bytes from buffer 'source' 0186 * into already allocated 'dest' buffer of size 'maxOutputSize'. 0187 * Compression is guaranteed to succeed if 0188 * 'maxOutputSize' >= LZ4_compressBound(inputSize). 0189 * It also runs faster, so it's a recommended setting. 0190 * If the function cannot compress 'source' into a more limited 'dest' budget, 0191 * compression stops *immediately*, and the function result is zero. 0192 * As a consequence, 'dest' content is not valid. 0193 * 0194 * Return: Number of bytes written into buffer 'dest' 0195 * (necessarily <= maxOutputSize) or 0 if compression fails 0196 */ 0197 int LZ4_compress_default(const char *source, char *dest, int inputSize, 0198 int maxOutputSize, void *wrkmem); 0199 0200 /** 0201 * LZ4_compress_fast() - As LZ4_compress_default providing an acceleration param 0202 * @source: source address of the original data 0203 * @dest: output buffer address of the compressed data 0204 * @inputSize: size of the input data. Max supported value is LZ4_MAX_INPUT_SIZE 0205 * @maxOutputSize: full or partial size of buffer 'dest' 0206 * which must be already allocated 0207 * @acceleration: acceleration factor 0208 * @wrkmem: address of the working memory. 0209 * This requires 'workmem' of LZ4_MEM_COMPRESS. 0210 * 0211 * Same as LZ4_compress_default(), but allows to select an "acceleration" 0212 * factor. The larger the acceleration value, the faster the algorithm, 0213 * but also the lesser the compression. It's a trade-off. It can be fine tuned, 0214 * with each successive value providing roughly +~3% to speed. 0215 * An acceleration value of "1" is the same as regular LZ4_compress_default() 0216 * Values <= 0 will be replaced by LZ4_ACCELERATION_DEFAULT, which is 1. 0217 * 0218 * Return: Number of bytes written into buffer 'dest' 0219 * (necessarily <= maxOutputSize) or 0 if compression fails 0220 */ 0221 int LZ4_compress_fast(const char *source, char *dest, int inputSize, 0222 int maxOutputSize, int acceleration, void *wrkmem); 0223 0224 /** 0225 * LZ4_compress_destSize() - Compress as much data as possible 0226 * from source to dest 0227 * @source: source address of the original data 0228 * @dest: output buffer address of the compressed data 0229 * @sourceSizePtr: will be modified to indicate how many bytes where read 0230 * from 'source' to fill 'dest'. New value is necessarily <= old value. 0231 * @targetDestSize: Size of buffer 'dest' which must be already allocated 0232 * @wrkmem: address of the working memory. 0233 * This requires 'workmem' of LZ4_MEM_COMPRESS. 0234 * 0235 * Reverse the logic, by compressing as much data as possible 0236 * from 'source' buffer into already allocated buffer 'dest' 0237 * of size 'targetDestSize'. 0238 * This function either compresses the entire 'source' content into 'dest' 0239 * if it's large enough, or fill 'dest' buffer completely with as much data as 0240 * possible from 'source'. 0241 * 0242 * Return: Number of bytes written into 'dest' (necessarily <= targetDestSize) 0243 * or 0 if compression fails 0244 */ 0245 int LZ4_compress_destSize(const char *source, char *dest, int *sourceSizePtr, 0246 int targetDestSize, void *wrkmem); 0247 0248 /*-************************************************************************ 0249 * Decompression Functions 0250 **************************************************************************/ 0251 0252 /** 0253 * LZ4_decompress_fast() - Decompresses data from 'source' into 'dest' 0254 * @source: source address of the compressed data 0255 * @dest: output buffer address of the uncompressed data 0256 * which must be already allocated with 'originalSize' bytes 0257 * @originalSize: is the original and therefore uncompressed size 0258 * 0259 * Decompresses data from 'source' into 'dest'. 0260 * This function fully respect memory boundaries for properly formed 0261 * compressed data. 0262 * It is a bit faster than LZ4_decompress_safe(). 0263 * However, it does not provide any protection against intentionally 0264 * modified data stream (malicious input). 0265 * Use this function in trusted environment only 0266 * (data to decode comes from a trusted source). 0267 * 0268 * Return: number of bytes read from the source buffer 0269 * or a negative result if decompression fails. 0270 */ 0271 int LZ4_decompress_fast(const char *source, char *dest, int originalSize); 0272 0273 /** 0274 * LZ4_decompress_safe() - Decompression protected against buffer overflow 0275 * @source: source address of the compressed data 0276 * @dest: output buffer address of the uncompressed data 0277 * which must be already allocated 0278 * @compressedSize: is the precise full size of the compressed block 0279 * @maxDecompressedSize: is the size of 'dest' buffer 0280 * 0281 * Decompresses data from 'source' into 'dest'. 0282 * If the source stream is detected malformed, the function will 0283 * stop decoding and return a negative result. 0284 * This function is protected against buffer overflow exploits, 0285 * including malicious data packets. It never writes outside output buffer, 0286 * nor reads outside input buffer. 0287 * 0288 * Return: number of bytes decompressed into destination buffer 0289 * (necessarily <= maxDecompressedSize) 0290 * or a negative result in case of error 0291 */ 0292 int LZ4_decompress_safe(const char *source, char *dest, int compressedSize, 0293 int maxDecompressedSize); 0294 0295 /** 0296 * LZ4_decompress_safe_partial() - Decompress a block of size 'compressedSize' 0297 * at position 'source' into buffer 'dest' 0298 * @source: source address of the compressed data 0299 * @dest: output buffer address of the decompressed data which must be 0300 * already allocated 0301 * @compressedSize: is the precise full size of the compressed block. 0302 * @targetOutputSize: the decompression operation will try 0303 * to stop as soon as 'targetOutputSize' has been reached 0304 * @maxDecompressedSize: is the size of destination buffer 0305 * 0306 * This function decompresses a compressed block of size 'compressedSize' 0307 * at position 'source' into destination buffer 'dest' 0308 * of size 'maxDecompressedSize'. 0309 * The function tries to stop decompressing operation as soon as 0310 * 'targetOutputSize' has been reached, reducing decompression time. 0311 * This function never writes outside of output buffer, 0312 * and never reads outside of input buffer. 0313 * It is therefore protected against malicious data packets. 0314 * 0315 * Return: the number of bytes decoded in the destination buffer 0316 * (necessarily <= maxDecompressedSize) 0317 * or a negative result in case of error 0318 * 0319 */ 0320 int LZ4_decompress_safe_partial(const char *source, char *dest, 0321 int compressedSize, int targetOutputSize, int maxDecompressedSize); 0322 0323 /*-************************************************************************ 0324 * LZ4 HC Compression 0325 **************************************************************************/ 0326 0327 /** 0328 * LZ4_compress_HC() - Compress data from `src` into `dst`, using HC algorithm 0329 * @src: source address of the original data 0330 * @dst: output buffer address of the compressed data 0331 * @srcSize: size of the input data. Max supported value is LZ4_MAX_INPUT_SIZE 0332 * @dstCapacity: full or partial size of buffer 'dst', 0333 * which must be already allocated 0334 * @compressionLevel: Recommended values are between 4 and 9, although any 0335 * value between 1 and LZ4HC_MAX_CLEVEL will work. 0336 * Values >LZ4HC_MAX_CLEVEL behave the same as 16. 0337 * @wrkmem: address of the working memory. 0338 * This requires 'wrkmem' of size LZ4HC_MEM_COMPRESS. 0339 * 0340 * Compress data from 'src' into 'dst', using the more powerful 0341 * but slower "HC" algorithm. Compression is guaranteed to succeed if 0342 * `dstCapacity >= LZ4_compressBound(srcSize) 0343 * 0344 * Return : the number of bytes written into 'dst' or 0 if compression fails. 0345 */ 0346 int LZ4_compress_HC(const char *src, char *dst, int srcSize, int dstCapacity, 0347 int compressionLevel, void *wrkmem); 0348 0349 /** 0350 * LZ4_resetStreamHC() - Init an allocated 'LZ4_streamHC_t' structure 0351 * @streamHCPtr: pointer to the 'LZ4_streamHC_t' structure 0352 * @compressionLevel: Recommended values are between 4 and 9, although any 0353 * value between 1 and LZ4HC_MAX_CLEVEL will work. 0354 * Values >LZ4HC_MAX_CLEVEL behave the same as 16. 0355 * 0356 * An LZ4_streamHC_t structure can be allocated once 0357 * and re-used multiple times. 0358 * Use this function to init an allocated `LZ4_streamHC_t` structure 0359 * and start a new compression. 0360 */ 0361 void LZ4_resetStreamHC(LZ4_streamHC_t *streamHCPtr, int compressionLevel); 0362 0363 /** 0364 * LZ4_loadDictHC() - Load a static dictionary into LZ4_streamHC 0365 * @streamHCPtr: pointer to the LZ4HC_stream_t 0366 * @dictionary: dictionary to load 0367 * @dictSize: size of dictionary 0368 * 0369 * Use this function to load a static dictionary into LZ4HC_stream. 0370 * Any previous data will be forgotten, only 'dictionary' 0371 * will remain in memory. 0372 * Loading a size of 0 is allowed. 0373 * 0374 * Return : dictionary size, in bytes (necessarily <= 64 KB) 0375 */ 0376 int LZ4_loadDictHC(LZ4_streamHC_t *streamHCPtr, const char *dictionary, 0377 int dictSize); 0378 0379 /** 0380 * LZ4_compress_HC_continue() - Compress 'src' using data from previously 0381 * compressed blocks as a dictionary using the HC algorithm 0382 * @streamHCPtr: Pointer to the previous 'LZ4_streamHC_t' structure 0383 * @src: source address of the original data 0384 * @dst: output buffer address of the compressed data, 0385 * which must be already allocated 0386 * @srcSize: size of the input data. Max supported value is LZ4_MAX_INPUT_SIZE 0387 * @maxDstSize: full or partial size of buffer 'dest' 0388 * which must be already allocated 0389 * 0390 * These functions compress data in successive blocks of any size, using 0391 * previous blocks as dictionary. One key assumption is that previous 0392 * blocks (up to 64 KB) remain read-accessible while 0393 * compressing next blocks. There is an exception for ring buffers, 0394 * which can be smaller than 64 KB. 0395 * Ring buffers scenario is automatically detected and handled by 0396 * LZ4_compress_HC_continue(). 0397 * Before starting compression, state must be properly initialized, 0398 * using LZ4_resetStreamHC(). 0399 * A first "fictional block" can then be designated as 0400 * initial dictionary, using LZ4_loadDictHC() (Optional). 0401 * Then, use LZ4_compress_HC_continue() 0402 * to compress each successive block. Previous memory blocks 0403 * (including initial dictionary when present) must remain accessible 0404 * and unmodified during compression. 0405 * 'dst' buffer should be sized to handle worst case scenarios, using 0406 * LZ4_compressBound(), to ensure operation success. 0407 * If, for any reason, previous data blocks can't be preserved unmodified 0408 * in memory during next compression block, 0409 * you must save it to a safer memory space, using LZ4_saveDictHC(). 0410 * Return value of LZ4_saveDictHC() is the size of dictionary 0411 * effectively saved into 'safeBuffer'. 0412 * 0413 * Return: Number of bytes written into buffer 'dst' or 0 if compression fails 0414 */ 0415 int LZ4_compress_HC_continue(LZ4_streamHC_t *streamHCPtr, const char *src, 0416 char *dst, int srcSize, int maxDstSize); 0417 0418 /** 0419 * LZ4_saveDictHC() - Save static dictionary from LZ4HC_stream 0420 * @streamHCPtr: pointer to the 'LZ4HC_stream_t' structure 0421 * @safeBuffer: buffer to save dictionary to, must be already allocated 0422 * @maxDictSize: size of 'safeBuffer' 0423 * 0424 * If previously compressed data block is not guaranteed 0425 * to remain available at its memory location, 0426 * save it into a safer place (char *safeBuffer). 0427 * Note : you don't need to call LZ4_loadDictHC() afterwards, 0428 * dictionary is immediately usable, you can therefore call 0429 * LZ4_compress_HC_continue(). 0430 * 0431 * Return : saved dictionary size in bytes (necessarily <= maxDictSize), 0432 * or 0 if error. 0433 */ 0434 int LZ4_saveDictHC(LZ4_streamHC_t *streamHCPtr, char *safeBuffer, 0435 int maxDictSize); 0436 0437 /*-********************************************* 0438 * Streaming Compression Functions 0439 ***********************************************/ 0440 0441 /** 0442 * LZ4_resetStream() - Init an allocated 'LZ4_stream_t' structure 0443 * @LZ4_stream: pointer to the 'LZ4_stream_t' structure 0444 * 0445 * An LZ4_stream_t structure can be allocated once 0446 * and re-used multiple times. 0447 * Use this function to init an allocated `LZ4_stream_t` structure 0448 * and start a new compression. 0449 */ 0450 void LZ4_resetStream(LZ4_stream_t *LZ4_stream); 0451 0452 /** 0453 * LZ4_loadDict() - Load a static dictionary into LZ4_stream 0454 * @streamPtr: pointer to the LZ4_stream_t 0455 * @dictionary: dictionary to load 0456 * @dictSize: size of dictionary 0457 * 0458 * Use this function to load a static dictionary into LZ4_stream. 0459 * Any previous data will be forgotten, only 'dictionary' 0460 * will remain in memory. 0461 * Loading a size of 0 is allowed. 0462 * 0463 * Return : dictionary size, in bytes (necessarily <= 64 KB) 0464 */ 0465 int LZ4_loadDict(LZ4_stream_t *streamPtr, const char *dictionary, 0466 int dictSize); 0467 0468 /** 0469 * LZ4_saveDict() - Save static dictionary from LZ4_stream 0470 * @streamPtr: pointer to the 'LZ4_stream_t' structure 0471 * @safeBuffer: buffer to save dictionary to, must be already allocated 0472 * @dictSize: size of 'safeBuffer' 0473 * 0474 * If previously compressed data block is not guaranteed 0475 * to remain available at its memory location, 0476 * save it into a safer place (char *safeBuffer). 0477 * Note : you don't need to call LZ4_loadDict() afterwards, 0478 * dictionary is immediately usable, you can therefore call 0479 * LZ4_compress_fast_continue(). 0480 * 0481 * Return : saved dictionary size in bytes (necessarily <= dictSize), 0482 * or 0 if error. 0483 */ 0484 int LZ4_saveDict(LZ4_stream_t *streamPtr, char *safeBuffer, int dictSize); 0485 0486 /** 0487 * LZ4_compress_fast_continue() - Compress 'src' using data from previously 0488 * compressed blocks as a dictionary 0489 * @streamPtr: Pointer to the previous 'LZ4_stream_t' structure 0490 * @src: source address of the original data 0491 * @dst: output buffer address of the compressed data, 0492 * which must be already allocated 0493 * @srcSize: size of the input data. Max supported value is LZ4_MAX_INPUT_SIZE 0494 * @maxDstSize: full or partial size of buffer 'dest' 0495 * which must be already allocated 0496 * @acceleration: acceleration factor 0497 * 0498 * Compress buffer content 'src', using data from previously compressed blocks 0499 * as dictionary to improve compression ratio. 0500 * Important : Previous data blocks are assumed to still 0501 * be present and unmodified ! 0502 * If maxDstSize >= LZ4_compressBound(srcSize), 0503 * compression is guaranteed to succeed, and runs faster. 0504 * 0505 * Return: Number of bytes written into buffer 'dst' or 0 if compression fails 0506 */ 0507 int LZ4_compress_fast_continue(LZ4_stream_t *streamPtr, const char *src, 0508 char *dst, int srcSize, int maxDstSize, int acceleration); 0509 0510 /** 0511 * LZ4_setStreamDecode() - Instruct where to find dictionary 0512 * @LZ4_streamDecode: the 'LZ4_streamDecode_t' structure 0513 * @dictionary: dictionary to use 0514 * @dictSize: size of dictionary 0515 * 0516 * Use this function to instruct where to find the dictionary. 0517 * Setting a size of 0 is allowed (same effect as reset). 0518 * 0519 * Return: 1 if OK, 0 if error 0520 */ 0521 int LZ4_setStreamDecode(LZ4_streamDecode_t *LZ4_streamDecode, 0522 const char *dictionary, int dictSize); 0523 0524 /** 0525 * LZ4_decompress_safe_continue() - Decompress blocks in streaming mode 0526 * @LZ4_streamDecode: the 'LZ4_streamDecode_t' structure 0527 * @source: source address of the compressed data 0528 * @dest: output buffer address of the uncompressed data 0529 * which must be already allocated 0530 * @compressedSize: is the precise full size of the compressed block 0531 * @maxDecompressedSize: is the size of 'dest' buffer 0532 * 0533 * This decoding function allows decompression of multiple blocks 0534 * in "streaming" mode. 0535 * Previously decoded blocks *must* remain available at the memory position 0536 * where they were decoded (up to 64 KB) 0537 * In the case of a ring buffers, decoding buffer must be either : 0538 * - Exactly same size as encoding buffer, with same update rule 0539 * (block boundaries at same positions) In which case, 0540 * the decoding & encoding ring buffer can have any size, 0541 * including very small ones ( < 64 KB). 0542 * - Larger than encoding buffer, by a minimum of maxBlockSize more bytes. 0543 * maxBlockSize is implementation dependent. 0544 * It's the maximum size you intend to compress into a single block. 0545 * In which case, encoding and decoding buffers do not need 0546 * to be synchronized, and encoding ring buffer can have any size, 0547 * including small ones ( < 64 KB). 0548 * - _At least_ 64 KB + 8 bytes + maxBlockSize. 0549 * In which case, encoding and decoding buffers do not need to be 0550 * synchronized, and encoding ring buffer can have any size, 0551 * including larger than decoding buffer. W 0552 * Whenever these conditions are not possible, save the last 64KB of decoded 0553 * data into a safe buffer, and indicate where it is saved 0554 * using LZ4_setStreamDecode() 0555 * 0556 * Return: number of bytes decompressed into destination buffer 0557 * (necessarily <= maxDecompressedSize) 0558 * or a negative result in case of error 0559 */ 0560 int LZ4_decompress_safe_continue(LZ4_streamDecode_t *LZ4_streamDecode, 0561 const char *source, char *dest, int compressedSize, 0562 int maxDecompressedSize); 0563 0564 /** 0565 * LZ4_decompress_fast_continue() - Decompress blocks in streaming mode 0566 * @LZ4_streamDecode: the 'LZ4_streamDecode_t' structure 0567 * @source: source address of the compressed data 0568 * @dest: output buffer address of the uncompressed data 0569 * which must be already allocated with 'originalSize' bytes 0570 * @originalSize: is the original and therefore uncompressed size 0571 * 0572 * This decoding function allows decompression of multiple blocks 0573 * in "streaming" mode. 0574 * Previously decoded blocks *must* remain available at the memory position 0575 * where they were decoded (up to 64 KB) 0576 * In the case of a ring buffers, decoding buffer must be either : 0577 * - Exactly same size as encoding buffer, with same update rule 0578 * (block boundaries at same positions) In which case, 0579 * the decoding & encoding ring buffer can have any size, 0580 * including very small ones ( < 64 KB). 0581 * - Larger than encoding buffer, by a minimum of maxBlockSize more bytes. 0582 * maxBlockSize is implementation dependent. 0583 * It's the maximum size you intend to compress into a single block. 0584 * In which case, encoding and decoding buffers do not need 0585 * to be synchronized, and encoding ring buffer can have any size, 0586 * including small ones ( < 64 KB). 0587 * - _At least_ 64 KB + 8 bytes + maxBlockSize. 0588 * In which case, encoding and decoding buffers do not need to be 0589 * synchronized, and encoding ring buffer can have any size, 0590 * including larger than decoding buffer. W 0591 * Whenever these conditions are not possible, save the last 64KB of decoded 0592 * data into a safe buffer, and indicate where it is saved 0593 * using LZ4_setStreamDecode() 0594 * 0595 * Return: number of bytes decompressed into destination buffer 0596 * (necessarily <= maxDecompressedSize) 0597 * or a negative result in case of error 0598 */ 0599 int LZ4_decompress_fast_continue(LZ4_streamDecode_t *LZ4_streamDecode, 0600 const char *source, char *dest, int originalSize); 0601 0602 /** 0603 * LZ4_decompress_safe_usingDict() - Same as LZ4_setStreamDecode() 0604 * followed by LZ4_decompress_safe_continue() 0605 * @source: source address of the compressed data 0606 * @dest: output buffer address of the uncompressed data 0607 * which must be already allocated 0608 * @compressedSize: is the precise full size of the compressed block 0609 * @maxDecompressedSize: is the size of 'dest' buffer 0610 * @dictStart: pointer to the start of the dictionary in memory 0611 * @dictSize: size of dictionary 0612 * 0613 * This decoding function works the same as 0614 * a combination of LZ4_setStreamDecode() followed by 0615 * LZ4_decompress_safe_continue() 0616 * It is stand-alone, and doesn't need an LZ4_streamDecode_t structure. 0617 * 0618 * Return: number of bytes decompressed into destination buffer 0619 * (necessarily <= maxDecompressedSize) 0620 * or a negative result in case of error 0621 */ 0622 int LZ4_decompress_safe_usingDict(const char *source, char *dest, 0623 int compressedSize, int maxDecompressedSize, const char *dictStart, 0624 int dictSize); 0625 0626 /** 0627 * LZ4_decompress_fast_usingDict() - Same as LZ4_setStreamDecode() 0628 * followed by LZ4_decompress_fast_continue() 0629 * @source: source address of the compressed data 0630 * @dest: output buffer address of the uncompressed data 0631 * which must be already allocated with 'originalSize' bytes 0632 * @originalSize: is the original and therefore uncompressed size 0633 * @dictStart: pointer to the start of the dictionary in memory 0634 * @dictSize: size of dictionary 0635 * 0636 * This decoding function works the same as 0637 * a combination of LZ4_setStreamDecode() followed by 0638 * LZ4_decompress_fast_continue() 0639 * It is stand-alone, and doesn't need an LZ4_streamDecode_t structure. 0640 * 0641 * Return: number of bytes decompressed into destination buffer 0642 * (necessarily <= maxDecompressedSize) 0643 * or a negative result in case of error 0644 */ 0645 int LZ4_decompress_fast_usingDict(const char *source, char *dest, 0646 int originalSize, const char *dictStart, int dictSize); 0647 0648 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |