1 /*********************************************************************************************************************************** 2 Compression Helper 3 4 Abstract compression types so that the calling code does not need to worry about the individual characteristics of the compression 5 type. All compress calls should use this module rather than the individual filters, even if a specific compression type is required. 6 ***********************************************************************************************************************************/ 7 #ifndef COMMON_COMPRESS_HELPER_H 8 #define COMMON_COMPRESS_HELPER_H 9 10 #include <stdbool.h> 11 12 /*********************************************************************************************************************************** 13 Available compression types 14 ***********************************************************************************************************************************/ 15 typedef enum 16 { 17 compressTypeNone, // No compression 18 compressTypeBz2, // bzip2 19 compressTypeGz, // gzip 20 compressTypeLz4, // lz4 21 compressTypeZst, // zstandard 22 23 // These types have not been implemented but are included here so older versions can identify compression types added by future 24 // versions. In that sense this list is speculative, but these seem to be all the types that are likely to be added in the 25 // foreseeable future. 26 compressTypeXz, // xz/lzma 27 } CompressType; 28 29 #include <common/type/string.h> 30 #include <common/io/filter/group.h> 31 32 /*********************************************************************************************************************************** 33 Compression types as a regexp. In the future this regexp will be generated automatically at build time but we want to wait until the 34 build code is migrated to C to do that. For now just define it statically since we don't expect it to change very often. If a 35 supported type is not in this list then it should cause an integration test to fail. 36 ***********************************************************************************************************************************/ 37 #define COMPRESS_TYPE_REGEXP "(\\.gz|\\.lz4|\\.zst|\\.xz|\\.bz2)" 38 39 /*********************************************************************************************************************************** 40 Functions 41 ***********************************************************************************************************************************/ 42 // Get enum from a compression type string 43 CompressType compressTypeEnum(const String *type); 44 45 // Check that a valid compress type is compiled into this binary. Errors when the compress type is not present. 46 void compressTypePresent(CompressType type); 47 48 // Get string representation of a compression type. This is the extension without the period. 49 const String *compressTypeStr(CompressType type); 50 51 // Get compression type from a (file) name by checking the extension. If the extension is not a supported compression type then 52 // compressType none is returned, even if the file is compressed with some unknown type. 53 CompressType compressTypeFromName(const String *name); 54 55 // Compression filter for the specified type. Error when compress type is none or invalid. 56 IoFilter *compressFilter(CompressType type, int level); 57 58 // Compression/decompression filter based on string type and a parameter list. This is useful when a filter must be created on a 59 // remote system since the filter type and parameters can be passed through a protocol. 60 IoFilter *compressFilterVar(const String *filterType, const VariantList *filterParamList); 61 62 // Decompression filter for the specified type. Error when compress type is none or invalid. 63 IoFilter *decompressFilter(CompressType type); 64 65 // Get extension for the current compression type 66 const String *compressExtStr(CompressType type); 67 68 // Add extension for current compression type to the file 69 void compressExtCat(String *file, CompressType type); 70 71 // Remove the specified compression extension. Error when the extension is not correct. 72 String *compressExtStrip(const String *file, CompressType type); 73 74 #endif 75