block_header_encoder.c File Reference

Encodes Block Header for .xz files. More...

`#include "common.h"`
`#include "check.h"`

## Functions

lzma_ret | lzma_block_header_size (lzma_block *block)
| Calculate Block Header Size. More...
lzma_ret | lzma_block_header_encode (const lzma_block *block, uint8_t *out)
| Encode Block Header. More...

## Detailed Description

Encodes Block Header for .xz files.

## Function Documentation

## lzma_block_header_size()

lzma_ret lzma_block_header_size | ( | lzma_block * | block | ) |

Calculate Block Header Size.

Calculate the minimum size needed for the Block Header field using the settings specified in the lzma_block structure. Note that it is OK to increase the calculated header_size value as long as it is a multiple of four and doesn't exceed LZMA_BLOCK_HEADER_SIZE_MAX. Increasing header_size just means that lzma_block_header_encode() will add Header Padding.

Returns
  - LZMA_OK: Size calculated successfully and stored to block->header_size.
  - LZMA_OPTIONS_ERROR: Unsupported version, filters or filter options.
  - LZMA_PROG_ERROR: Invalid values like compressed_size == 0.

Note
  This doesn't check that all the options are valid i.e. this may return LZMA_OK even if lzma_block_header_encode() or lzma_block_encoder() would fail. If you want to validate the filter chain, consider using lzma_memlimit_encoder() which as a side-effect validates the filter chain.

References lzma_filter_flags_size(), LZMA_FILTERS_MAX, LZMA_OPTIONS_ERROR, LZMA_PROG_ERROR, lzma_vli_size(), LZMA_VLI_UNKNOWN, and return_if_error.

## lzma_block_header_encode()

lzma_ret lzma_block_header_encode | ( | const lzma_block * | block,
|  | uint8_t * | out
| ) |  |

Encode Block Header.

The caller must have calculated the size of the Block Header already with lzma_block_header_size(). If a value larger than the one calculated by lzma_block_header_size() is used, the Block Header will be padded to the specified size.

Parameters

  out | Beginning of the output buffer. This must be at least block->header_size bytes.
  block | Block options to be encoded.

Returns
  - LZMA_OK: Encoding was successful. block->header_size bytes were written to output buffer.
  - LZMA_OPTIONS_ERROR: Invalid or unsupported options.
  - LZMA_PROG_ERROR: Invalid arguments, for example block->header_size is invalid or block->filters is NULL.

References lzma_block_unpadded_size(), lzma_filter_flags_encode(), LZMA_FILTERS_MAX, LZMA_PROG_ERROR, lzma_vli_encode(), lzma_vli_is_valid, LZMA_VLI_UNKNOWN, and return_if_error.