xref: /freebsd-src/contrib/xz/src/xz/coder.h (revision 3b35e7ee8de9b0260149a2b77e87a2b9c7a36244)
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 /// Array of these hold the entries specified with --block-list.
34 typedef struct {
35 	/// Uncompressed size of the Block
36 	uint64_t size;
37 
38 	/// Filter chain to use for this Block (chains[chain_num])
39 	unsigned chain_num;
40 } block_list_entry;
41 
42 
43 /// Operation mode of the command line tool. This is set in args.c and read
44 /// in several files.
45 extern enum operation_mode opt_mode;
46 
47 /// File format to use when encoding or what format(s) to accept when
48 /// decoding. This is a global because it's needed also in suffix.c.
49 /// This is set in args.c.
50 extern enum format_type opt_format;
51 
52 /// If true, the compression settings are automatically adjusted down if
53 /// they exceed the memory usage limit.
54 extern bool opt_auto_adjust;
55 
56 /// If true, stop after decoding the first stream.
57 extern bool opt_single_stream;
58 
59 /// If non-zero, start a new .xz Block after every opt_block_size bytes
60 /// of input. This has an effect only when compressing to the .xz format.
61 extern uint64_t opt_block_size;
62 
63 /// List of block size and filter chain pointer pairs.
64 extern block_list_entry *opt_block_list;
65 
66 /// Size of the largest Block that was specified in --block-list.
67 /// This is used to limit the block_size option of multithreaded encoder.
68 /// It's waste of memory to specify a too large block_size and reducing
69 /// it might even allow using more threads in some cases.
70 ///
71 /// NOTE: If the last entry in --block-list is the special value of 0
72 /// (which gets converted to UINT64_MAX), it counts here as UINT64_MAX too.
73 /// This way the multithreaded encoder's Block size won't be reduced.
74 extern uint64_t block_list_largest;
75 
76 /// Bitmask indicating which filter chains we specified in --block-list.
77 extern uint32_t block_list_chain_mask;
78 
79 /// Set the integrity check type used when compressing
80 extern void coder_set_check(lzma_check check);
81 
82 /// Set preset number
83 extern void coder_set_preset(uint32_t new_preset);
84 
85 /// Enable extreme mode
86 extern void coder_set_extreme(void);
87 
88 /// Add a filter to the custom filter chain
89 extern void coder_add_filter(lzma_vli id, void *options);
90 
91 /// Set and partially validate compression settings. This can also be used
92 /// in decompression or test mode with the raw format.
93 extern void coder_set_compression_settings(void);
94 
95 /// Compress or decompress the given file
96 extern void coder_run(const char *filename);
97 
98 #ifndef NDEBUG
99 /// Free the memory allocated for the coder and kill the worker threads.
100 extern void coder_free(void);
101 #endif
102 
103 /// Create filter chain from string
104 extern void coder_add_filters_from_str(const char *filter_str);
105 
106 /// Add or overwrite a filter that can be used by the block-list.
107 extern void coder_add_block_filters(const char *str, size_t slot);
108