summaryrefslogtreecommitdiffstats
path: root/lz4.h
blob: 0251157577fd9d6c12b41a39867c1d2b3132e674 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*

   LZ4 - Fast LZ compression algorithm

   Header File

   Copyright (C) 2011, Yann Collet.

   BSD License



   Redistribution and use in source and binary forms, with or without

   modification, are permitted provided that the following conditions are

   met:

  

       * Redistributions of source code must retain the above copyright

   notice, this list of conditions and the following disclaimer.

       * Redistributions in binary form must reproduce the above

   copyright notice, this list of conditions and the following disclaimer

   in the documentation and/or other materials provided with the

   distribution.

  

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR

   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT

   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,

   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT

   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,

   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY

   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/
#pragma once


#if defined (__cplusplus)

extern "C" {
#endif



//****************************

// Simple Functions

//****************************


int LZ4_compress   (char* source, char* dest, int isize);
int LZ4_uncompress (char* source, char* dest, int osize);

/*

LZ4_compress() :

	return : the number of bytes in compressed buffer dest

	note : destination buffer must be already allocated. 

		To avoid any problem, size it to handle worst cases situations (input data not compressible)

		Worst case size is : "inputsize + 0.4%", with "0.4%" being at least 8 bytes.



LZ4_uncompress() :

	osize  : is the output size, therefore the original size

	return : the number of bytes read in the source buffer

			 If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction

			 This version never writes beyond dest + osize, and is therefore protected against malicious data packets

	note 2 : destination buffer must be already allocated

*/


//****************************

// Advanced Functions

//****************************


int LZ4_uncompress_unknownOutputSize (char* source, char* dest, int isize, int maxOutputSize);

/*

LZ4_uncompress_unknownOutputSize() :

	isize  : is the input size, therefore the compressed size

	maxOutputSize : is the size of the destination buffer (which must be already allocated)

	return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)

			 If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction

			 This version never writes beyond dest + maxOutputSize, and is therefore protected against malicious data packets

	note   : This version is a bit slower than LZ4_uncompress

*/


int LZ4_compressCtx(void** ctx, char* source,  char* dest, int isize);

/*

LZ4_compressCtx() :

	This function explicitly handles the CTX memory structure.

	It avoids allocating/deallocating memory between each call, improving performance when malloc is time-consuming.

	Note : when memory is allocated into the stack (default mode), there is no "malloc" penalty.

	Therefore, this function is mostly useful when memory is allocated into the heap (it requires increasing HASH_LOG value beyond STACK_LIMIT)



	On first call : provide a *ctx=NULL; It will be automatically allocated.

	On next calls : reuse the same ctx pointer.

	Use different pointers for different threads when doing multi-threading.



	note : performance difference is small, mostly noticeable in HeapMode when repetitively calling the compression function over many small segments.

*/


#if defined (__cplusplus)

}
#endif