54 #if defined(HAVE_ENCODERS) && defined(MYTHREAD_ENABLED)
127 memlimit_too_small(
uint64_t memory_usage)
144 if (!lzma_check_is_supported(
check))
162 "presets may vary between software "
185 "the LZMA1 filter"));
193 "with the .xz format"));
210 "incompatible with --flush-timeout"));
216 "mode due to --flush-timeout"));
227 # ifdef MYTHREAD_ENABLED
232 memory_usage = lzma_stream_encoder_mt_memusage(
241 memory_usage = lzma_raw_encoder_memusage(
filters);
246 memory_usage = lzma_raw_decoder_memusage(
filters);
269 if (memory_usage <= memory_limit)
276 memlimit_too_small(memory_usage);
281 # ifdef MYTHREAD_ENABLED
291 memlimit_too_small(memory_usage);
293 memory_usage = lzma_stream_encoder_mt_memusage(
298 }
while (memory_usage > memory_limit);
301 "from %s to %s to not exceed "
302 "the memory usage limit of %s MiB"),
310 if (memory_usage <= memory_limit)
319 memlimit_too_small(memory_usage);
337 memlimit_too_small(memory_usage);
339 memory_usage = lzma_raw_encoder_memusage(
filters);
344 if (memory_usage <= memory_limit)
355 "from %s MiB to %s MiB to not exceed "
356 "the memory usage limit of %s MiB"),
374 static const uint8_t magic[6] = { 0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00 };
376 && memcmp(
in_buf.
u8, magic,
sizeof(magic)) == 0;
409 if (
d != dict_size || dict_size == 0)
417 for (
size_t i = 0;
i < 8; ++
i)
448 # ifdef MYTHREAD_ENABLED
450 ret = lzma_stream_encoder_mt(
454 ret = lzma_stream_encoder(
489 else if (is_format_lzma())
499 if (is_format_lzma())
508 switch (init_format) {
523 ret = lzma_stream_decoder(&
strm,
529 ret = lzma_alone_decoder(&
strm,
575 if (*next_block_remaining > 0) {
588 *block_remaining = *next_block_remaining;
591 *next_block_remaining -= *block_remaining;
607 *next_block_remaining
643 bool success =
false;
710 if (block_remaining == 0)
748 &next_block_remaining,
827 lzma_memusage(&
strm));
880 bool success =
false;
910 const bool is_passthru = init_ret
913 = pair->
src_st.st_size <= 0
lzma_check
Type of the integrity check (Check ID)
const lzma_allocator const uint8_t size_t in_size
void coder_free(void)
Free the memory allocated for the coder and kill the worker threads.
static lzma_stream strm
Stream used to communicate with liblzma.
uint64_t * opt_block_list
static void lzma_attribute((__noreturn__))
void coder_set_check(lzma_check new_check)
Set the integrity check type used when compressing.
static bool coder_normal(file_pair *pair)
Compress or decompress using liblzma.
void coder_set_extreme(void)
Enable extreme mode.
static void forget_filter_chain(void)
void coder_set_compression_settings(void)
static lzma_check check
Integrity check type.
static uint32_t preset_number
Number of the preset (0-9)
static enum coder_init_ret coder_init(file_pair *pair)
coder_init_ret
Return value type for coder_init().
enum format_type opt_format
void coder_add_filter(lzma_vli id, void *options)
Add a filter to the custom filter chain.
static void split_block(uint64_t *block_remaining, uint64_t *next_block_remaining, size_t *list_pos)
static bool check_default
This becomes false if the –check=CHECK option is used.
static lzma_filter filters[LZMA_FILTERS_MAX+1]
Filters needed for all encoding all formats, and also decoding in raw data.
static uint32_t filters_count
Number of filters. Zero indicates that we are using a preset.
static bool coder_write_output(file_pair *pair)
static io_buf in_buf
Input and output buffers.
void coder_run(const char *filename)
Compress or decompress the given file.
bool opt_single_stream
If true, stop after decoding the first stream.
static bool coder_passthru(file_pair *pair)
void coder_set_preset(uint32_t new_preset)
Set preset number.
enum operation_mode opt_mode
#define LZMA_IGNORE_CHECK
#define LZMA_CONCATENATED
#define LZMA_PRESET_LEVEL_MASK
Mask for preset level.
#define LZMA_TELL_UNSUPPORTED_CHECK
#define LZMA_PRESET_DEFAULT
Default compression preset.
#define LZMA_PRESET_EXTREME
Extreme compression preset.
#define LZMA_FILTER_DELTA
Filter ID.
bool io_write(file_pair *pair, const io_buf *buf, size_t size)
Writes a buffer to the destination file.
bool io_open_dest(file_pair *pair)
Open the destination file.
void io_close(file_pair *pair, bool success)
Closes the file descriptors and frees possible allocated memory.
void io_fix_src_pos(file_pair *pair, size_t rewind_size)
Fix the position in src_fd.
file_pair * io_open_src(const char *src_name)
Open the source file.
size_t io_read(file_pair *pair, io_buf *buf, size_t size)
Reads from the source file to a buffer.
#define LZMA_FILTERS_MAX
Maximum number of filters in a chain.
void hardware_threads_set(uint32_t n)
Set the maximum number of worker threads.
uint32_t hardware_threads_get(void)
Get the maximum number of worker threads.
uint64_t hardware_memlimit_get(enum operation_mode mode)
Get the current memory usage limit for compression or decompression.
RZ_API void Ht_() free(HtName_(Ht) *ht)
static const char struct stat static buf struct stat static buf static vhangup int options
#define LZMA_FILTER_LZMA2
LZMA2 Filter ID.
#define LZMA_FILTER_LZMA1
LZMA1 Filter ID.
assert(limit<=UINT32_MAX/2)
void message_progress_end(bool success)
Finishes the progress message if we were in verbose mode.
void message_filename(const char *src_name)
Set the name of the current file and possibly print it too.
void message_mem_needed(enum message_verbosity v, uint64_t memusage)
Display how much memory was needed and how much the limit was.
void message_error(const char *fmt,...)
void message_warning(const char *fmt,...)
void message_filters_show(enum message_verbosity v, const lzma_filter *filters)
Print the filter chain.
void message_progress_start(lzma_stream *strm, bool is_passthru, uint64_t in_size)
Start progress info handling.
void message_progress_update(void)
const char * message_strm(lzma_ret code)
Convert lzma_ret to a string.
void message_fatal(const char *fmt,...)
@ V_WARNING
Errors and warnings.
@ V_ERROR
Only error messages.
uint64_t opt_flush_timeout
Number of milliseconds to between LZMA_SYNC_FLUSHes.
void mytime_set_start_time(void)
Store the time when (de)compression was started.
static struct sockaddr static addrlen static backlog const void static flags void flags
volatile sig_atomic_t user_abort
bool flush_needed
For –flush-timeout: True when flushing is needed.
struct stat src_st
Stat of the source file.
bool src_eof
True once end of the source file has been detected.
void * options
Pointer to filter-specific options structure.
uint64_t block_size
Maximum uncompressed size of a Block.
uint32_t threads
Number of worker threads to use.
lzma_check check
Integrity check type.
Options specific to the LZMA1 and LZMA2 filters.
uint32_t dict_size
Dictionary size in bytes.
Passing data to and from liblzma.
uint64_t uncompressed_size
Common includes, definitions, and prototypes.
const char * uint64_to_str(uint64_t value, uint32_t slot)
Convert uint64_t to a string.
uint64_t round_up_to_mib(uint64_t n)
Round an integer up to the next full MiB and convert to MiB.
uint8_t u8[IO_BUFFER_SIZE]
uint64_t lzma_vli
Variable-length integer type.
#define LZMA_VLI_UNKNOWN
VLI value to denote that the value is unknown.
lzma_ret
Return values used by several functions in liblzma.
@ LZMA_PROG_ERROR
Programming error.
@ LZMA_DATA_ERROR
Data is corrupt.
@ LZMA_FORMAT_ERROR
Memory usage limit was reached.
@ LZMA_STREAM_END
End of stream was reached.
@ LZMA_UNSUPPORTED_CHECK
Cannot calculate the integrity check.
@ LZMA_NO_CHECK
Input stream has no integrity check.
@ LZMA_OK
Operation completed successfully.
lzma_action
The ‘action’ argument for lzma_code()
@ LZMA_SYNC_FLUSH
Make all the input available at output.
@ LZMA_FINISH
Finish the coding operation.
@ LZMA_RUN
Continue coding.
@ LZMA_FULL_BARRIER
Finish encoding of the current Block.
#define LZMA_STREAM_INIT
Initialization for lzma_stream.