xref: /freebsd/contrib/xz/src/xz/coder.h (revision a91a2465)
1 // SPDX-License-Identifier: 0BSD
2 
3 ///////////////////////////////////////////////////////////////////////////////
4 //
5 /// \file       coder.h
6 /// \brief      Compresses or uncompresses a file
7 //
8 //  Authors:    Lasse Collin
9 //              Jia Tan
10 //
11 ///////////////////////////////////////////////////////////////////////////////
12 
13 enum operation_mode {
14 	MODE_COMPRESS,
15 	MODE_DECOMPRESS,
16 	MODE_TEST,
17 	MODE_LIST,
18 };
19 
20 
21 // NOTE: The order of these is significant in suffix.c.
22 enum format_type {
23 	FORMAT_AUTO,
24 	FORMAT_XZ,
25 	FORMAT_LZMA,
26 #ifdef HAVE_LZIP_DECODER
27 	FORMAT_LZIP,
28 #endif
29 	FORMAT_RAW,
30 };
31 
32 
33 /// Simple struct to track Block metadata specified through the
34 /// --block-list option.
35 typedef struct {
36 	/// Uncompressed size of the Block
37 	uint64_t size;
38 
39 	/// Index into the filters[] representing the filter chain to use
40 	/// for this Block.
41 	uint32_t filters_index;
42 } block_list_entry;
43 
44 
45 /// Operation mode of the command line tool. This is set in args.c and read
46 /// in several files.
47 extern enum operation_mode opt_mode;
48 
49 /// File format to use when encoding or what format(s) to accept when
50 /// decoding. This is a global because it's needed also in suffix.c.
51 /// This is set in args.c.
52 extern enum format_type opt_format;
53 
54 /// If true, the compression settings are automatically adjusted down if
55 /// they exceed the memory usage limit.
56 extern bool opt_auto_adjust;
57 
58 /// If true, stop after decoding the first stream.
59 extern bool opt_single_stream;
60 
61 /// If non-zero, start a new .xz Block after every opt_block_size bytes
62 /// of input. This has an effect only when compressing to the .xz format.
63 extern uint64_t opt_block_size;
64 
65 /// List of block size and filter chain pointer pairs.
66 extern block_list_entry *opt_block_list;
67 
68 /// Set the integrity check type used when compressing
69 extern void coder_set_check(lzma_check check);
70 
71 /// Set preset number
72 extern void coder_set_preset(uint32_t new_preset);
73 
74 /// Enable extreme mode
75 extern void coder_set_extreme(void);
76 
77 /// Add a filter to the custom filter chain
78 extern void coder_add_filter(lzma_vli id, void *options);
79 
80 /// Set and partially validate compression settings. This can also be used
81 /// in decompression or test mode with the raw format.
82 extern void coder_set_compression_settings(void);
83 
84 /// Compress or decompress the given file
85 extern void coder_run(const char *filename);
86 
87 #ifndef NDEBUG
88 /// Free the memory allocated for the coder and kill the worker threads.
89 extern void coder_free(void);
90 #endif
91 
92 /// Create filter chain from string
93 extern void coder_add_filters_from_str(const char *filter_str);
94 
95 /// Add or overwrite a filter that can be used by the block-list.
96 extern void coder_add_block_filters(const char *str, size_t slot);
97