Reference
Function references are listed here.
batch_compress(input_file)
Compresses a file using multiple compression configurations and returns performance metrics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_file |
str
|
The path to the input file to be compressed. |
required |
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]: A list of dictionaries containing metrics for each compression configuration, including file sizes and compression times. |
Source code in xcompress/batch_ops.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
batch_compress_decompress(input_file, out_folder, skip_if_file_exists)
Compresses and decompresses a file using multiple compression configurations, returns performance metrics for each configuration. Not reachable from cli or menu. For getting batch results for all defined config files. These results are used to train CSM module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_file |
str
|
The path to the input file to be compressed and decompressed. |
required |
out_folder |
str
|
The directory where output files will be saved. |
required |
skip_if_file_exists |
bool
|
If True, skips compression if the output file already exists. |
required |
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]: A list of dictionaries containing metrics for each compression configuration, including file sizes and times for compression and decompression. |
Source code in xcompress/batch_ops.py
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 |
|
get_configs()
Retrieves compression configuration data from JSON files located in the compression_configs
directory.
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]: A list of dictionaries, each containing the configuration data loaded from a JSON file. |
Source code in xcompress/batch_ops.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
benchmark()
Main function for running benchmarks. Allows the user to select configurations, benchmark type, and output options.
Source code in xcompress/benchmark.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
benchmark_param(selected_config_names, benchmark_type, filename, output_filename, output_to_file=False, output_plots=False)
Benchmarks the selected compression configurations and either outputs results to a file or displays them.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selected_config_names |
List[str]
|
List of names of selected configurations (compression methods). |
required |
benchmark_type |
str
|
Type of benchmark ("compress" or "compress_decompress"). |
required |
filename |
str
|
Path to the input file. |
required |
output_filename |
str
|
Path to the output file. |
required |
output_to_file |
bool
|
If True, results are saved to a file. |
False
|
output_plots |
bool
|
If True, plots are generated and displayed. |
False
|
Source code in xcompress/benchmark.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
|
display_select_benchmark_menu(menu_options, selected_index)
Displays the benchmark type selection menu.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
menu_options |
List[str]
|
List of benchmark type options. |
required |
selected_index |
int
|
Index of the currently selected option. |
required |
Source code in xcompress/benchmark.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
print_menu(options, selected_rows, config_count, current_row)
Prints the menu for selecting compression algorithms.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
options |
List[Dict[str, str]]
|
List of defined compression algorithms with configuration files. |
required |
selected_rows |
Set[int]
|
Set of indices of selected options. |
required |
config_count |
int
|
Total number of configuration options. |
required |
current_row |
int
|
The currently selected row in the menu. |
required |
Source code in xcompress/benchmark.py
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 |
|
read_boolean_input(prompt)
Reads a boolean input from the user.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt |
str
|
The prompt message to display. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
True if 'y' is entered, False if 'n' is entered. |
Source code in xcompress/benchmark.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|
select_benchmark_type()
Allows the user to select a benchmark type from a menu.
Returns:
Name | Type | Description |
---|---|---|
str |
The selected benchmark type ("compress" or "compress_decompress"), or None if canceled. |
Source code in xcompress/benchmark.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
select_config(prev_configs=None)
Allows the user to select compression configurations from a menu.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prev_configs |
Set[int]
|
Previously selected configurations. |
None
|
Returns:
Type | Description |
---|---|
Set[int]: Set of indices of selected configurations. |
Source code in xcompress/benchmark.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
brute_force_compression()
Prompts the user for input and output file details, and performs brute-force compression using all available configurations and selects the one with the minimum compressed size.
Source code in xcompress/brute_force.py
87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
brute_force_param(filename, out_folder, delete_except_minimum=False)
Performs brute-force compression using all available configurations and selects the one with the minimum compressed size.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
Path to the input file. |
required |
out_folder |
str
|
Directory where output files are stored. |
required |
output_filename |
str
|
Path for the output file. |
required |
delete_except_minimum |
bool
|
If True, deletes all files except the one with the minimum compressed size. |
False
|
Source code in xcompress/brute_force.py
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 74 75 76 77 78 79 80 81 82 83 84 |
|
print_menu(selected_row, options)
Prints a menu for selecting compression modes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selected_row |
int
|
The index of the currently selected row. |
required |
options |
List[str]
|
List of compression mode options. |
required |
Source code in xcompress/brute_force.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
compress_with_config(config_data, input_file, output_file='')
Compresses a file using specified compression configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_data |
dict
|
Dictionary containing compression parameters, executable path, and file parameter placeholders. |
required |
input_file |
str
|
Path to the input file to be compressed. |
required |
output_file |
str
|
Path to the output file. If not provided, defaults to generating a file based on config. |
''
|
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple containing the output file path and the compression execution time in nanoseconds. |
Source code in xcompress/compress.py
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
create_config()
Collects configuration inputs from the user, creates a configuration dictionary, and saves it to a file in the 'compression_configs' folder.
Source code in xcompress/create_config.py
106 107 108 109 110 111 112 113 114 115 |
|
create_config_param(name, executable_path, input_file_param, output_file_param, compression_params, decompression_params, extension)
Creates a configuration dictionary from given parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the configuration. |
required |
executable_path |
str
|
Path to the executable. |
required |
input_file_param |
str
|
Input file parameter. |
required |
output_file_param |
str
|
Output file parameter. |
required |
compression_params |
list
|
List of compression parameters. |
required |
decompression_params |
list
|
List of decompression parameters. |
required |
extension |
str
|
File extension. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
A configuration dictionary. |
Source code in xcompress/create_config.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
get_config_input()
Prompts the user for configuration parameters and returns a dictionary containing the inputs.
Returns:
Name | Type | Description |
---|---|---|
dict |
A dictionary with configuration parameters. |
Source code in xcompress/create_config.py
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 |
|
save_config_to_file(config, folder_path)
Saves the configuration dictionary to a JSON file in the specified folder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
dict
|
The configuration dictionary. |
required |
folder_path |
str
|
The path to the folder where the config file will be saved (compression_configs preferred). |
required |
Source code in xcompress/create_config.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
model_compression()
Displays the model compression menu and handles user selection.
Source code in xcompress/csm.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
model_compression_param(mode, filename, output_filename)
Executes compression based on the selected algorithm and mode.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mode |
str
|
The compression mode (fast-compress, fast-decompress or best-compress). |
required |
filename |
str
|
The input file to compress. |
required |
output_filename |
str
|
The name of the output file. |
required |
Source code in xcompress/csm.py
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 |
|
print_menu(selected_row, options)
Prints the menu options, highlighting the selected option.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selected_row |
int
|
Index of the currently selected option. |
required |
options |
list of str
|
List of menu options to display. |
required |
Source code in xcompress/csm.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
decompress_with_config(config_data, input_file, output_file='')
Decompresses a file using the specified configuration parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_data |
dict
|
A dictionary containing configuration details such as executable path, decompression parameters, and file parameters. |
required |
input_file |
str
|
Path to the file that needs to be decompressed. |
required |
output_file |
str
|
Path to the file where the decompressed output should be saved. If not specified, a default name based on the input file is used. |
''
|
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple containing: - output_file (str): Path to the decompressed file. - execution_time_ns (float): Time taken for decompression in nanoseconds. |
Source code in xcompress/decompress.py
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 74 75 76 77 78 79 80 81 82 83 84 85 |
|
detect_algorithm(filename, mode)
Detects the likely compression algorithm for a given file based on its characteristics and the specified mode.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
Path to the file for which the algorithm needs to be detected. |
required |
mode |
str
|
Compression mode to be used for detection ("fast-compression", "best-compression","fast-decompression"). |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
The name of the detected compression algorithm. |
Source code in xcompress/llm_model.py
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 |
|
CustomHelpAction
Bases: Action
A custom argparse action that displays help information for both the main parser and its subparsers.
This action overrides the default help behavior to include detailed help messages for all available subcommands.
Methods:
Name | Description |
---|---|
__init__ |
Initializes the CustomHelpAction instance. |
__call__ |
Displays help information for the parser and its subparsers. |
Source code in xcompress/main.py
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 |
|
__call__(parser, namespace, values, option_string=None)
Displays help information for the parser and its subparsers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parser |
ArgumentParser
|
The parser to display help for. |
required |
namespace |
Namespace
|
The namespace for the parsed values. |
required |
values |
any
|
The values for the action (default: None). |
required |
option_string |
str
|
The option string (default: None). |
None
|
Source code in xcompress/main.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
__init__(option_strings, dest=argparse.SUPPRESS, default=argparse.SUPPRESS, help=None)
Initializes the CustomHelpAction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
option_strings |
list
|
The option strings for this action. |
required |
dest |
str
|
The destination for the parsed value (default: argparse.SUPPRESS). |
SUPPRESS
|
default |
any
|
The default value (default: argparse.SUPPRESS). |
SUPPRESS
|
help |
str
|
The help message (default: None). |
None
|
Source code in xcompress/main.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
main()
The main entry point for the XCompress tool.
This function sets up the command-line argument parser and handles user input through either command-line arguments or an interactive menu. - For command-line arguments, it parses the arguments and calls the appropriate function based on the specified command. - For interactive mode, it displays a menu for the user to select various functionalities such as selecting a compression algorithm, benchmarking, creating configurations, and visualizing results.
Source code in xcompress/main.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
|
print_menu(selected_row)
Prints the main menu for the XCompress tool.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selected_row |
int
|
The index of the currently selected menu item to highlight. |
required |
Source code in xcompress/main.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
print_menu(options, selected_row, config_count)
Displays a menu for selecting a compression algorithm from a list of available configurations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
options |
list of dict
|
List of available compression configurations. Each configuration is a dictionary with a "name" key. |
required |
selected_row |
int
|
The index of the currently selected menu item to highlight. |
required |
config_count |
int
|
The total number of configuration files found. |
required |
Source code in xcompress/select_compression.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
select_compression()
Allows the user to select a compression algorithm from a menu and apply it to a specified file.
The function loads available compression configurations from a folder, displays them in a menu, and allows the user to navigate and select one. After selection, it prompts the user for input and output filenames and performs the compression.
Source code in xcompress/select_compression.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
select_compression_param(selected_config_name, filename, output_filename)
Selects a specific compression configuration and applies it to the input file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selected_config_name |
str
|
The name of the selected compression configuration. |
required |
filename |
str
|
The path to the file to compress. |
required |
output_filename |
str
|
The path to save the compressed file (optional; defaults to input filename with an appropriate extension if not provided). |
required |
Source code in xcompress/select_compression.py
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 |
|
bin_usc(usc_value)
Bins the unique symbol count (USC) value into a multiple of 50. To use USC as a feature to train ai model, selected features must have limited values. If USC is given raw, accuracy decreases. To prevent this, USC values have been divided into groups of 50.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
usc_value |
int
|
The unique symbol count value. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
The binned unique symbol count. |
Source code in xcompress/util.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
clear_screen()
Clears the terminal screen.
The method used to clear the screen depends on the operating system: - Windows: Uses 'cls' command. - Other systems (e.g., Unix-based): Uses 'clear' command.
Source code in xcompress/util.py
6 7 8 9 10 11 12 13 14 15 16 17 |
|
count_unique_symbols(file_path)
Counts the number of unique symbols in a text file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
The path to the text file. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
The number of unique symbols in the file. |
Source code in xcompress/util.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
get_config(configs, selected_algorithm)
Retrieves a configuration dictionary based on the selected algorithm name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
configs |
list of dict
|
List of configuration dictionaries. |
required |
selected_algorithm |
str
|
The name of the desired algorithm to find. |
required |
Returns:
Type | Description |
---|---|
dict or None: The configuration dictionary for the selected algorithm, or None if not found. |
Source code in xcompress/util.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
get_file_size(file_path)
Gets the size of a file in bytes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
The path to the file. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
The size of the file in bytes. |
Source code in xcompress/util.py
113 114 115 116 117 118 119 120 121 122 123 124 |
|
load_configs(folder_path)
Loads configuration files from a specified folder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
folder_path |
str
|
The path to the folder containing configuration files. |
required |
Returns:
Type | Description |
---|---|
list of dict: A list of configuration dictionaries loaded from JSON files. |
Source code in xcompress/util.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
round_to_class(file_size_bytes)
Rounds the file size to a specific class based on byte ranges.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_size_bytes |
int
|
The size of the file in bytes. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
A string representing the rounded size class ("1kb", "10kb", "100kb", "1mb", "10mb", or "100mb"). |
Source code in xcompress/util.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
read_results_from_file(file_path)
Reads the results in a JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
Path to JSON file. |
required |
Returns:
Type | Description |
---|---|
list of dict: A combined list of results from all specified JSON files. |
Source code in xcompress/visualization.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
visualization()
Main function to handle the visualization process: - Prompts the user for file paths. - Reads results from the specified files. - Generates and displays a bar chart visualizing the benchmark results.
Source code in xcompress/visualization.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
visualization_param(file_path)
Generates and displays a bar chart visualizing compression benchmark results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
Path to JSON file containing metrics like compressed size, compression time, and optionally decompression time. |
required |
Source code in xcompress/visualization.py
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|