coder.c File Reference

Compresses or uncompresses a file. More...

`#include "private.h"`

## Enumerations

enum | coder_init_ret { CODER_INIT_NORMAL , CODER_INIT_PASSTHRU , CODER_INIT_ERROR }
| Return value type for coder_init(). More...

## Functions

void | coder_set_check (lzma_check new_check)
| Set the integrity check type used when compressing. More...
static void | forget_filter_chain (void)
void | coder_set_preset (uint32_t new_preset)
| Set preset number. More...
void | coder_set_extreme (void)
| Enable extreme mode. More...
void | coder_add_filter (lzma_vli id, void *options)
| Add a filter to the custom filter chain. More...
static void | lzma_attribute ((__noreturn__))
void | coder_set_compression_settings (void)
static enum coder_init_ret | coder_init (file_pair *pair)
static void | split_block (uint64_t *block_remaining, uint64_t *next_block_remaining, size_t *list_pos)
static bool | coder_write_output (file_pair *pair)
static bool | coder_normal (file_pair *pair)
| Compress or decompress using liblzma. More...
static bool | coder_passthru (file_pair *pair)
void | coder_run (const char *filename)
| Compress or decompress the given file. More...
void | coder_free (void)
| Free the memory allocated for the coder and kill the worker threads. More...

## Variables

enum operation_mode | opt_mode = MODE_COMPRESS
enum format_type | opt_format = FORMAT_AUTO
bool | opt_auto_adjust = true
bool | opt_single_stream = false
| If true, stop after decoding the first stream. More...
uint64_t | opt_block_size = 0
uint64_t * | opt_block_list = NULL
static lzma_stream | strm = LZMA_STREAM_INIT
| Stream used to communicate with liblzma. More...
static lzma_filter | filters [LZMA_FILTERS_MAX+1]
| Filters needed for all encoding all formats, and also decoding in raw data. More...
static io_buf | in_buf
| Input and output buffers. More...
static io_buf | out_buf
static uint32_t | filters_count = 0
| Number of filters. Zero indicates that we are using a preset. More...
static uint32_t | preset_number = LZMA_PRESET_DEFAULT
| Number of the preset (0-9) More...
static lzma_check | check
| Integrity check type. More...
static bool | check_default = true
| This becomes false if the –check=CHECK option is used. More...

## Detailed Description

Compresses or uncompresses a file.

## Enumeration Type Documentation

## coder_init_ret

enum coder_init_ret

Return value type for coder_init().

## Function Documentation

## coder_set_check()

void coder_set_check | ( | lzma_check | new_check | ) |

Set the integrity check type used when compressing.

References check, and check_default.

## coder_set_preset()

void coder_set_preset | ( | uint32_t | new_preset | ) |

Set preset number.

References LZMA_PRESET_LEVEL_MASK, and preset_number.

## coder_set_extreme()

void coder_set_extreme | ( | void |  | ) |

Enable extreme mode.

References LZMA_PRESET_EXTREME, and preset_number.

## coder_add_filter()

void coder_add_filter | ( | lzma_vli | id,
|  | void * | options
| ) |  |

Add a filter to the custom filter chain.

References filters_count, LZMA_FILTERS_MAX, and message_fatal().

## coder_init()

static enum coder_init_ret coder_init | ( | file_pair * | pair | ) |

static

Detect the input file type (for now, this done only when decompressing), and initialize an appropriate coder. Return value indicates if a normal liblzma-based coder was initialized (CODER_INIT_NORMAL), if passthru mode should be used (CODER_INIT_PASSTHRU), or if an error occurred (CODER_INIT_ERROR).

## split_block()

static void split_block | ( | uint64_t * | block_remaining,
|  | uint64_t * | next_block_remaining,
|  | size_t * | list_pos
| ) |  |

static

Resolve conflicts between opt_block_size and opt_block_list in single threaded mode. We want to default to opt_block_list, except when it is larger than opt_block_size. If this is the case for the current Block at *list_pos, then we break into smaller Blocks. Otherwise advance to the next Block in opt_block_list, and break apart if needed.

## coder_normal()

static bool coder_normal | ( | file_pair * | pair | ) |

static

Compress or decompress using liblzma.

References LZMA_FINISH, LZMA_RUN, and file_pair::src_eof.

## coder_passthru()

static bool coder_passthru | ( | file_pair * | pair | ) |

static

Copy from input file to output file without processing the data in any way. This is used only when trying to decompress unrecognized files with –decompress –stdout –force, so the output is always stdout.

References lzma_stream::avail_in, in_buf, io_read(), io_write(), message_progress_update(), strm, lzma_stream::total_in, lzma_stream::total_out, and user_abort.

## coder_run()

void coder_run | ( | const char * | filename | ) |

Compress or decompress the given file.

References filename, io_open_src(), message_filename(), and opt_mode.

## coder_free()

void coder_free | ( | void |  | ) |

Free the memory allocated for the coder and kill the worker threads.

References lzma_end(), and strm.

## Variable Documentation

## opt_mode

enum operation_mode opt_mode = MODE_COMPRESS

Operation mode of the command line tool. This is set in args.c and read in several files.

Referenced by coder_run(), message_filename(), message_mem_needed(), and mytime_get_flush_timeout().

## opt_format

enum format_type opt_format = FORMAT_AUTO

File format to use when encoding or what format(s) to accept when decoding. This is a global because it's needed also in suffix.c. This is set in args.c.

Referenced by list_file(), and uncompressed_name().

## opt_auto_adjust

bool opt_auto_adjust = true

If true, the compression settings are automatically adjusted down if they exceed the memory usage limit.

## opt_single_stream

bool opt_single_stream = false

If true, stop after decoding the first stream.

## opt_block_size

uint64_t opt_block_size = 0

If non-zero, start a new .xz Block after every opt_block_size bytes of input. This has an effect only when compressing to the .xz format.

## opt_block_list

uint64_t* opt_block_list = NULL

This is non-NULL if –block-list was used. This contains the Block sizes as an array that is terminated with 0.

## strm

lzma_stream strm = LZMA_STREAM_INIT

static

Stream used to communicate with liblzma.

Referenced by coder_free(), coder_passthru(), lzma_code(), lzma_easy_encoder(), lzma_end(), lzma_filters_update(), lzma_get_check(), lzma_get_progress(), lzma_memlimit_get(), lzma_memlimit_set(), lzma_memusage(), lzma_strm_init(), and message_progress_start().

## filters

lzma_filter filters[LZMA_FILTERS_MAX+1]

static

Filters needed for all encoding all formats, and also decoding in raw data.

Referenced by get_options(), lzma_filters_update(), lzma_stream_encoder_mt_memusage(), message_filters_show(), and message_filters_to_str().

## in_buf

io_buf in_buf

static

Input and output buffers.

Referenced by coder_passthru().

## filters_count

uint32_t filters_count = 0

static

Number of filters. Zero indicates that we are using a preset.

Referenced by coder_add_filter().

## preset_number

uint32_t preset_number = LZMA_PRESET_DEFAULT

static

Number of the preset (0-9)

Referenced by coder_set_extreme(), and coder_set_preset().

## check

lzma_check check

static

Integrity check type.

Referenced by coder_set_check(), lzma_check_finish(), lzma_check_init(), lzma_check_update(), lzma_easy_encoder(), lzma_sha256_finish(), lzma_sha256_init(), and lzma_sha256_update().

## check_default

bool check_default = true

static

This becomes false if the –check=CHECK option is used.

Referenced by coder_set_check().