XZ Utils 5.3.4alpha
|
Encode into MicroLZMA format. More...
#include "lzma_encoder.h"
Data Structures | |
struct | lzma_microlzma_coder |
Functions | |
static lzma_ret | microlzma_encode (void *coder_ptr, const lzma_allocator *allocator, const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size, lzma_action action) |
static void | microlzma_encoder_end (void *coder_ptr, const lzma_allocator *allocator) |
static lzma_ret | microlzma_encoder_init (lzma_next_coder *next, const lzma_allocator *allocator, const lzma_options_lzma *options) |
lzma_ret | lzma_microlzma_encoder (lzma_stream *strm, const lzma_options_lzma *options) |
MicroLZMA encoder. More... | |
Encode into MicroLZMA format.
lzma_ret lzma_microlzma_encoder | ( | lzma_stream * | strm, |
const lzma_options_lzma * | options | ||
) |
MicroLZMA encoder.
The MicroLZMA format is a raw LZMA stream whose first byte (always 0x00) has been replaced with bitwise-negation of the LZMA properties (lc/lp/pb). This encoding ensures that the first byte of MicroLZMA stream is never 0x00. There is no end of payload marker and thus the uncompressed size must be stored separately. For the best error detection the dictionary size should be stored separately as well but alternatively one may use the uncompressed size as the dictionary size when decoding.
With the MicroLZMA encoder, lzma_code() behaves slightly unusually. The action argument must be LZMA_FINISH and the return value will never be LZMA_OK. Thus the encoding is always done with a single lzma_code() after the initialization. The benefit of the combination of initialization function and lzma_code() is that memory allocations can be re-used for better performance.
lzma_code() will try to encode as much input as is possible to fit into the given output buffer. If not all input can be encoded, the stream will be finished without encoding all the input. The caller must check both input and output buffer usage after lzma_code() (total_in and total_out in lzma_stream can be convenient). Often lzma_code() can fill the output buffer completely if there is a lot of input, but sometimes a few bytes may remain unused because the next LZMA symbol would require more space.
lzma_stream.avail_out must be at least 6. Otherwise LZMA_PROG_ERROR will be returned.
The LZMA dictionary should be reasonably low to speed up the encoder re-initialization. A good value is bigger than the resulting uncompressed size of most of the output chunks. For example, if output size is 4 KiB, dictionary size of 32 KiB or 64 KiB is good. If the data compresses extremely well, even 128 KiB may be useful.
The MicroLZMA format and this encoder variant were made with the EROFS file system in mind. This format may be convenient in other embedded uses too where many small streams are needed. XZ Embedded includes a decoder for this format.
References lzma_next_strm_init.