32 enum sequence next_sequence;
66 while (*in_pos < in_size || coder->sequence == SEQ_LZMA)
67 switch (coder->sequence) {
79 coder->need_properties =
true;
80 coder->need_dictionary_reset =
true;
81 }
else if (coder->need_dictionary_reset) {
88 coder->uncompressed_size = (
control & 0x1F) << 16;
89 coder->sequence = SEQ_UNCOMPRESSED_1;
96 coder->need_properties =
false;
97 coder->next_sequence = SEQ_PROPERTIES;
99 }
else if (coder->need_properties) {
103 coder->next_sequence = SEQ_LZMA;
109 coder->lzma.reset(coder->lzma.coder,
118 coder->sequence = SEQ_COMPRESSED_0;
119 coder->next_sequence = SEQ_COPY;
122 if (coder->need_dictionary_reset) {
125 coder->need_dictionary_reset =
false;
133 case SEQ_UNCOMPRESSED_1:
135 coder->sequence = SEQ_UNCOMPRESSED_2;
138 case SEQ_UNCOMPRESSED_2:
139 coder->uncompressed_size +=
in[(*in_pos)++] + 1U;
140 coder->sequence = SEQ_COMPRESSED_0;
141 coder->lzma.set_uncompressed(coder->lzma.coder,
142 coder->uncompressed_size);
145 case SEQ_COMPRESSED_0:
147 coder->sequence = SEQ_COMPRESSED_1;
150 case SEQ_COMPRESSED_1:
151 coder->compressed_size +=
in[(*in_pos)++] + 1U;
152 coder->sequence = coder->next_sequence;
159 coder->lzma.reset(coder->lzma.coder, &coder->options);
161 coder->sequence = SEQ_LZMA;
167 const size_t in_start = *
in_pos;
170 const lzma_ret ret = coder->lzma.code(coder->lzma.coder,
174 const size_t in_used = *
in_pos - in_start;
175 if (in_used > coder->compressed_size)
178 coder->compressed_size -= in_used;
187 if (coder->compressed_size != 0)
190 coder->sequence = SEQ_CONTROL;
197 if (coder->compressed_size != 0)
200 coder->sequence = SEQ_CONTROL;
249 ||
options->preset_dict_size == 0;
297 if (
props[0] == 40) {
const lzma_allocator const uint8_t size_t * in_pos
const lzma_allocator const uint8_t size_t in_size
const lzma_allocator * allocator
const lzma_allocator const uint8_t * in
const lzma_filter * filters
const lzma_allocator const uint8_t * props
static const char struct stat static buf struct stat static buf static vhangup int options
lzma_ret lzma_lz_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters, lzma_ret(*lz_init)(lzma_lz_decoder *lz, const lzma_allocator *allocator, const void *options, lzma_lz_options *lz_options))
static void dict_reset(lzma_dict *dict)
static void dict_write(lzma_dict *restrict dict, const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size, size_t *restrict left)
Copies arbitrary amount of data into the dictionary.
#define LZMA_LZ_DECODER_INIT
lzma_ret lzma_lzma2_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
uint64_t lzma_lzma2_decoder_memusage(const void *options)
static lzma_ret lzma2_decode(void *coder_ptr, lzma_dict *restrict dict, const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size)
lzma_ret lzma_lzma2_props_decode(void **options, const lzma_allocator *allocator, const uint8_t *props, size_t props_size)
static void lzma2_decoder_end(void *coder_ptr, const lzma_allocator *allocator)
static lzma_ret lzma2_decoder_init(lzma_lz_decoder *lz, const lzma_allocator *allocator, const void *opt, lzma_lz_options *lz_options)
lzma_ret lzma_lzma_decoder_create(lzma_lz_decoder *lz, const lzma_allocator *allocator, const void *opt, lzma_lz_options *lz_options)
bool lzma_lzma_lclppb_decode(lzma_options_lzma *options, uint8_t byte)
Decodes the LZMA Properties byte (lc/lp/pb)
uint64_t lzma_lzma_decoder_memusage_nocheck(const void *options)
assert(limit<=UINT32_MAX/2)
Custom functions for memory handling.
void * coder
Data specific to the LZ-based decoder.
void(* end)(void *coder, const lzma_allocator *allocator)
Free allocated resources.
lzma_ret(* code)(void *coder, lzma_dict *restrict dict, const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size)
Function to decode from in[] to *dict.
size_t uncompressed_size
Uncompressed size of LZMA chunk.
lzma_lz_decoder lzma
LZMA decoder.
lzma_options_lzma options
bool need_dictionary_reset
Hold data and function pointers of the next filter in the chain.
Options specific to the LZMA1 and LZMA2 filters.
const uint8_t * preset_dict
Pointer to an initial dictionary.
uint32_t preset_dict_size
Size of the preset dictionary.
uint32_t dict_size
Dictionary size in bytes.
void * lzma_alloc(size_t size, const lzma_allocator *allocator) lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
Allocates memory.
lzma_ret
Return values used by several functions in liblzma.
@ LZMA_PROG_ERROR
Programming error.
@ LZMA_DATA_ERROR
Data is corrupt.
@ LZMA_MEM_ERROR
Cannot allocate memory.
@ LZMA_STREAM_END
End of stream was reached.
@ LZMA_OPTIONS_ERROR
Invalid or unsupported options.
@ LZMA_OK
Operation completed successfully.
void lzma_free(void *ptr, const lzma_allocator *allocator)
Frees memory.