1 /* SPDX-License-Identifier: LGPL-2.1-or-later */ 2 #pragma once 3 4 #if HAVE_BZIP2 5 #include <bzlib.h> 6 #endif 7 #include <lzma.h> 8 #include <sys/types.h> 9 #include <zlib.h> 10 11 #include "macro.h" 12 13 typedef enum ImportCompressType { 14 IMPORT_COMPRESS_UNKNOWN, 15 IMPORT_COMPRESS_UNCOMPRESSED, 16 IMPORT_COMPRESS_XZ, 17 IMPORT_COMPRESS_GZIP, 18 IMPORT_COMPRESS_BZIP2, 19 _IMPORT_COMPRESS_TYPE_MAX, 20 _IMPORT_COMPRESS_TYPE_INVALID = -EINVAL, 21 } ImportCompressType; 22 23 typedef struct ImportCompress { 24 ImportCompressType type; 25 bool encoding; 26 union { 27 lzma_stream xz; 28 z_stream gzip; 29 #if HAVE_BZIP2 30 bz_stream bzip2; 31 #endif 32 }; 33 } ImportCompress; 34 35 typedef int (*ImportCompressCallback)(const void *data, size_t size, void *userdata); 36 37 void import_compress_free(ImportCompress *c); 38 39 int import_uncompress_detect(ImportCompress *c, const void *data, size_t size); 40 void import_uncompress_force_off(ImportCompress *c); 41 int import_uncompress(ImportCompress *c, const void *data, size_t size, ImportCompressCallback callback, void *userdata); 42 43 int import_compress_init(ImportCompress *c, ImportCompressType t); 44 int import_compress(ImportCompress *c, const void *data, size_t size, void **buffer, size_t *buffer_size, size_t *buffer_allocated); 45 int import_compress_finish(ImportCompress *c, void **buffer, size_t *buffer_size, size_t *buffer_allocated); 46 47 const char* import_compress_type_to_string(ImportCompressType t) _const_; 48 ImportCompressType import_compress_type_from_string(const char *s) _pure_; 49