XZ Utils 5.3.4alpha
Functions
block_util.c File Reference

Utility functions to handle lzma_block. More...

#include "common.h"
#include "index.h"

Functions

lzma_ret lzma_block_compressed_size (lzma_block *block, lzma_vli unpadded_size)
 Validate and set Compressed Size according to Unpadded Size. More...
 
lzma_vli lzma_block_unpadded_size (const lzma_block *block)
 Calculate Unpadded Size. More...
 
lzma_vli lzma_block_total_size (const lzma_block *block)
 Calculate the total encoded size of a Block. More...
 

Detailed Description

Utility functions to handle lzma_block.

Function Documentation

◆ lzma_block_compressed_size()

lzma_ret lzma_block_compressed_size ( lzma_block block,
lzma_vli  unpadded_size 
)

Validate and set Compressed Size according to Unpadded Size.

Block Header stores Compressed Size, but Index has Unpadded Size. If the application has already parsed the Index and is now decoding Blocks, it can calculate Compressed Size from Unpadded Size. This function does exactly that with error checking:

  • Compressed Size calculated from Unpadded Size must be positive integer, that is, Unpadded Size must be big enough that after Block Header and Check fields there's still at least one byte for Compressed Size.
  • If Compressed Size was present in Block Header, the new value calculated from Unpadded Size is compared against the value from Block Header.
Note
This function must be called after decoding the Block Header field so that it can properly validate Compressed Size if it was present in Block Header.
Returns
- LZMA_OK: block->compressed_size was set successfully.
  • LZMA_DATA_ERROR: unpadded_size is too small compared to block->header_size and lzma_check_size(block->check).
  • LZMA_PROG_ERROR: Some values are invalid. For example, block->header_size must be a multiple of four and between 8 and 1024 inclusive.

References lzma_block_unpadded_size(), lzma_check_size(), LZMA_DATA_ERROR, and LZMA_PROG_ERROR.

◆ lzma_block_unpadded_size()

lzma_vli lzma_block_unpadded_size ( const lzma_block block)

Calculate Unpadded Size.

The Index field stores Unpadded Size and Uncompressed Size. The latter can be taken directly from the lzma_block structure after coding a Block, but Unpadded Size needs to be calculated from Block Header Size, Compressed Size, and size of the Check field. This is where this function is needed.

Returns
Unpadded Size on success, or zero on error.

Referenced by lzma_block_compressed_size(), lzma_block_header_encode(), and lzma_block_total_size().

◆ lzma_block_total_size()

lzma_vli lzma_block_total_size ( const lzma_block block)

Calculate the total encoded size of a Block.

This is equivalent to lzma_block_unpadded_size() except that the returned value includes the size of the Block Padding field.

Returns
On success, total encoded size of the Block. On error, zero is returned.

References lzma_block_unpadded_size(), LZMA_VLI_UNKNOWN, and vli_ceil4().