2 * LZ4 - Fast LZ compression algorithm
4 * Copyright (C) 2011-2020, Yann Collet.
6 BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are
12 * Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14 * Redistributions in binary form must reproduce the above
15 copyright notice, this list of conditions and the following disclaimer
16 in the documentation and/or other materials provided with the
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 You can contact the author at :
32 - LZ4 homepage : http://www.lz4.org
33 - LZ4 source repository : https://github.com/lz4/lz4
35 module chibackend
.pack
.liblz4
;
38 public nothrow @nogc @trusted:
41 /*------ Version ------*/
42 enum LZ4_VERSION_MAJOR
= 1; /* for breaking interface changes */
43 enum LZ4_VERSION_MINOR
= 9; /* for new (non-breaking) interface capabilities */
44 enum LZ4_VERSION_RELEASE
= 3; /* for tweaks, bug-fixes, or development */
47 /*-************************************
49 **************************************/
50 /*! LZ4_compress_default() :
51 * Compresses 'srcSize' bytes from buffer 'src'
52 * into already allocated 'dst' buffer of size 'dstCapacity'.
53 * Compression is guaranteed to succeed if 'dstCapacity' >= LZ4_compressBound(srcSize).
54 * It also runs faster, so it's a recommended setting.
55 * If the function cannot compress 'src' into a more limited 'dst' budget,
56 * compression stops *immediately*, and the function result is zero.
57 * In which case, 'dst' content is undefined (invalid).
58 * srcSize : max supported value is LZ4_MAX_INPUT_SIZE.
59 * dstCapacity : size of buffer 'dst' (which must be already allocated)
60 * @return : the number of bytes written into buffer 'dst' (necessarily <= dstCapacity)
61 * or 0 if compression fails
62 * Note : This function is protected against buffer overflow scenarios (never writes outside 'dst' buffer, nor read outside 'source' buffer).
64 int LZ4_compress_default (const(void)* src
, void* dst
, int srcSize
, int dstCapacity
);
66 /*! LZ4_decompress_safe() :
67 * compressedSize : is the exact complete size of the compressed block.
68 * dstCapacity : is the size of destination buffer (which must be already allocated), presumed an upper bound of decompressed size.
69 * @return : the number of bytes decompressed into destination buffer (necessarily <= dstCapacity)
70 * If destination buffer is not large enough, decoding will stop and output an error code (negative value).
71 * If the source stream is detected malformed, the function will stop decoding and return a negative result.
72 * Note 1 : This function is protected against malicious data packets :
73 * it will never writes outside 'dst' buffer, nor read outside 'source' buffer,
74 * even if the compressed block is maliciously modified to order the decoder to do these actions.
75 * In such case, the decoder stops immediately, and considers the compressed block malformed.
76 * Note 2 : compressedSize and dstCapacity must be provided to the function, the compressed block does not contain them.
77 * The implementation is free to send / store / derive this information in whichever way is most beneficial.
78 * If there is a need for a different format which bundles together both compressed data and its metadata, consider looking at lz4frame.h instead.
80 int LZ4_decompress_safe (const(void)* src
, void* dst
, int compressedSize
, int dstCapacity
);
83 /*-************************************
85 **************************************/
86 enum LZ4_MAX_INPUT_SIZE
= 0x7E000000; /* 2 113 929 216 bytes */
88 /*! LZ4_compressBound() :
89 Provides the maximum size that LZ4 compression may output in a "worst case" scenario (input data not compressible)
90 This function is primarily useful for memory allocation purposes (destination buffer size).
91 Macro LZ4_COMPRESSBOUND() is also provided for compilation-time evaluation (stack memory allocation for example).
92 Note that LZ4_compress_default() compresses faster when dstCapacity is >= LZ4_compressBound(srcSize)
93 inputSize : max supported value is LZ4_MAX_INPUT_SIZE
94 return : maximum output size in a "worst case" scenario
95 or 0, if input size is incorrect (too large or negative)
97 int LZ4_compressBound (int inputSize
);