Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1+ */
2 : #pragma once
3 :
4 : #include <unistd.h>
5 :
6 : #include "journal-def.h"
7 :
8 : const char* object_compressed_to_string(int compression);
9 : int object_compressed_from_string(const char *compression);
10 :
11 : int compress_blob_xz(const void *src, uint64_t src_size,
12 : void *dst, size_t dst_alloc_size, size_t *dst_size);
13 : int compress_blob_lz4(const void *src, uint64_t src_size,
14 : void *dst, size_t dst_alloc_size, size_t *dst_size);
15 :
16 4 : static inline int compress_blob(const void *src, uint64_t src_size,
17 : void *dst, size_t dst_alloc_size, size_t *dst_size) {
18 : int r;
19 : #if HAVE_LZ4
20 4 : r = compress_blob_lz4(src, src_size, dst, dst_alloc_size, dst_size);
21 4 : if (r == 0)
22 4 : return OBJECT_COMPRESSED_LZ4;
23 : #else
24 : r = compress_blob_xz(src, src_size, dst, dst_alloc_size, dst_size);
25 : if (r == 0)
26 : return OBJECT_COMPRESSED_XZ;
27 : #endif
28 0 : return r;
29 : }
30 :
31 : int decompress_blob_xz(const void *src, uint64_t src_size,
32 : void **dst, size_t *dst_alloc_size, size_t* dst_size, size_t dst_max);
33 : int decompress_blob_lz4(const void *src, uint64_t src_size,
34 : void **dst, size_t *dst_alloc_size, size_t* dst_size, size_t dst_max);
35 : int decompress_blob(int compression,
36 : const void *src, uint64_t src_size,
37 : void **dst, size_t *dst_alloc_size, size_t* dst_size, size_t dst_max);
38 :
39 : int decompress_startswith_xz(const void *src, uint64_t src_size,
40 : void **buffer, size_t *buffer_size,
41 : const void *prefix, size_t prefix_len,
42 : uint8_t extra);
43 : int decompress_startswith_lz4(const void *src, uint64_t src_size,
44 : void **buffer, size_t *buffer_size,
45 : const void *prefix, size_t prefix_len,
46 : uint8_t extra);
47 : int decompress_startswith(int compression,
48 : const void *src, uint64_t src_size,
49 : void **buffer, size_t *buffer_size,
50 : const void *prefix, size_t prefix_len,
51 : uint8_t extra);
52 :
53 : int compress_stream_xz(int fdf, int fdt, uint64_t max_bytes);
54 : int compress_stream_lz4(int fdf, int fdt, uint64_t max_bytes);
55 :
56 : int decompress_stream_xz(int fdf, int fdt, uint64_t max_size);
57 : int decompress_stream_lz4(int fdf, int fdt, uint64_t max_size);
58 :
59 : #if HAVE_LZ4
60 : # define compress_stream compress_stream_lz4
61 : # define COMPRESSED_EXT ".lz4"
62 : #else
63 : # define compress_stream compress_stream_xz
64 : # define COMPRESSED_EXT ".xz"
65 : #endif
66 :
67 : int decompress_stream(const char *filename, int fdf, int fdt, uint64_t max_bytes);
|