easy_encoder.c File Reference

Easy .xz Stream encoder initialization. More...

`#include "easy_preset.h"`

## Functions

lzma_ret | lzma_easy_encoder (lzma_stream *strm, uint32_t preset, lzma_check check)
| Initialize .xz Stream encoder using a preset number. More...

## Detailed Description

Easy .xz Stream encoder initialization.

## Function Documentation

## lzma_easy_encoder()

lzma_ret lzma_easy_encoder | ( | lzma_stream * | strm,
|  | uint32_t | preset,
|  | lzma_check | check
| ) |  |

Initialize .xz Stream encoder using a preset number.

This function is intended for those who just want to use the basic features if liblzma (that is, most developers out there).

Parameters

  strm | Pointer to lzma_stream that is at least initialized with LZMA_STREAM_INIT.
  preset | Compression preset to use. A preset consist of level number and zero or more flags. Usually flags aren't used, so preset is simply a number [0, 9] which match the options -0 ... -9 of the xz command line tool. Additional flags can be be set using bitwise-or with the preset level number, e.g. 6 | LZMA_PRESET_EXTREME.
  check | Integrity check type to use. See check.h for available checks. The xz command line tool defaults to LZMA_CHECK_CRC64, which is a good choice if you are unsure. LZMA_CHECK_CRC32 is good too as long as the uncompressed file is not many gigabytes.

Returns
  - LZMA_OK: Initialization succeeded. Use lzma_code() to encode your data.
  - LZMA_MEM_ERROR: Memory allocation failed.
  - LZMA_OPTIONS_ERROR: The given compression preset is not supported by this build of liblzma.
  - LZMA_UNSUPPORTED_CHECK: The given check type is not supported by this liblzma build.
  - LZMA_PROG_ERROR: One or more of the parameters have values that will never be valid. For example, strm == NULL.

If initialization fails (return value is not LZMA_OK), all the memory allocated for *strm by liblzma is always freed. Thus, there is no need to call lzma_end() after failed initialization.

If initialization succeeds, use lzma_code() to do the actual encoding. Valid values for ‘action’ (the second argument of lzma_code()) are LZMA_RUN, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, and LZMA_FINISH. In future, there may be compression levels or flags that don't support LZMA_SYNC_FLUSH.

References check, lzma_options_easy::filters, lzma_easy_preset(), LZMA_OPTIONS_ERROR, lzma_stream_encoder(), and strm.