-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathcompressor.h
73 lines (59 loc) · 1.87 KB
/
compressor.h
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
/* SPDX-License-Identifier: LGPL-2.1+ */
#ifndef foocompresshorhfoo
#define foocompresshorhfoo
#include <stdbool.h>
#include <stddef.h>
#if HAVE_LIBLZMA
# include <lzma.h>
#endif
#if HAVE_LIBZ
# include <zlib.h>
#endif
#if HAVE_LIBZSTD
# include <zstd.h>
#endif
#include "cacompression.h"
typedef enum CompressorOperation {
COMPRESSOR_UNINITIALIZED,
COMPRESSOR_ENCODE,
COMPRESSOR_DECODE,
} CompressorOperation;
typedef struct CompressorContext {
CompressorOperation operation;
CaCompressionType compressor;
union {
#if HAVE_LIBLZMA
lzma_stream xz;
#endif
#if HAVE_LIBZ
struct z_stream_s gzip;
#endif
#if HAVE_LIBZSTD
struct {
ZSTD_CStream *cstream;
ZSTD_DStream *dstream;
ZSTD_inBuffer input;
ZSTD_outBuffer output;
} zstd;
#endif
};
} CompressorContext;
#define COMPRESSOR_CONTEXT_INIT \
{ \
.operation = COMPRESSOR_UNINITIALIZED, \
.compressor = _CA_COMPRESSION_TYPE_INVALID, \
}
bool compressor_is_supported(CaCompressionType compressor);
int compressor_start_decode(CompressorContext *c, CaCompressionType compressor);
int compressor_start_encode(CompressorContext *c, CaCompressionType compressor);
void compressor_finish(CompressorContext *c);
int compressor_input(CompressorContext *c, const void *p, size_t sz);
enum {
COMPRESSOR_EOF,
COMPRESSOR_MORE,
COMPRESSOR_GOOD,
};
int compressor_decode(CompressorContext *c, void *p, size_t size, size_t *ret_done);
int compressor_encode(CompressorContext *c, bool finalize, void *p, size_t size, size_t *ret_done);
int detect_compression(const void *buffer, size_t size);
#endif