block_buffer_encoder.c File Reference

Single-call .xz Block encoder. More...

`#include "block_buffer_encoder.h"`
`#include "block_encoder.h"`
`#include "filter_encoder.h"`
`#include "lzma2_encoder.h"`
`#include "check.h"`

## Macros

#define | HEADERS_BOUND

## Functions

static uint64_t | lzma2_bound (uint64_t uncompressed_size)
uint64_t | lzma_block_buffer_bound64 (uint64_t uncompressed_size)
size_t | lzma_block_buffer_bound (size_t uncompressed_size)
| Calculate maximum output size for single-call Block encoding. More...
static lzma_ret | block_encode_uncompressed (lzma_block *block, const uint8_t *in, size_t in_size, uint8_t *out, size_t *out_pos, size_t out_size)
static lzma_ret | block_encode_normal (lzma_block *block, const lzma_allocator *allocator, const uint8_t *in, size_t in_size, uint8_t *out, size_t *out_pos, size_t out_size)
static lzma_ret | block_buffer_encode (lzma_block *block, const lzma_allocator *allocator, const uint8_t *in, size_t in_size, uint8_t *out, size_t *out_pos, size_t out_size, bool try_to_compress)
lzma_ret | lzma_block_buffer_encode (lzma_block *block, const lzma_allocator *allocator, const uint8_t *in, size_t in_size, uint8_t *out, size_t *out_pos, size_t out_size)
| Single-call .xz Block encoder. More...
lzma_ret | lzma_block_uncomp_encode (lzma_block *block, const uint8_t *in, size_t in_size, uint8_t *out, size_t *out_pos, size_t out_size)
| Single-call uncompressed .xz Block encoder. More...

## Detailed Description

Single-call .xz Block encoder.

## Macro Definition Documentation

## HEADERS_BOUND

#define HEADERS_BOUND

Value:
((1 + 1 + 2 * LZMA_VLI_BYTES_MAX + 3 + 4 \
+ LZMA_CHECK_SIZE_MAX + 3) & ~3)
LZMA_CHECK_SIZE_MAX
#define LZMA_CHECK_SIZE_MAX
Maximum size of a Check field.
Definition: check.h:102
LZMA_VLI_BYTES_MAX
#define LZMA_VLI_BYTES_MAX
Maximum supported encoded length of variable length integers.
Definition: vli.h:44

Estimate the maximum size of the Block Header and Check fields for a Block that uses LZMA2 uncompressed chunks. We could use lzma_block_header_size() but this is simpler.

Block Header Size + Block Flags + Compressed Size

- Uncompressed Size + Filter Flags for LZMA2 + CRC32 + Check and round up to the next multiple of four to take Header Padding into account.

## Function Documentation

## lzma_block_buffer_bound64()

uint64_t lzma_block_buffer_bound64 | ( | uint64_t | uncompressed_size | ) |

uint64_t version of lzma_block_buffer_bound(). It is used by stream_encoder_mt.c. Probably the original lzma_block_buffer_bound() should have been 64-bit, but fixing it would break the ABI.

## lzma_block_buffer_bound()

size_t lzma_block_buffer_bound | ( | size_t | uncompressed_size | ) |

Calculate maximum output size for single-call Block encoding.

This is equivalent to lzma_stream_buffer_bound() but for .xz Blocks. See the documentation of lzma_stream_buffer_bound().

## lzma_block_buffer_encode()

lzma_ret lzma_block_buffer_encode | ( | lzma_block * | block,
|  | const lzma_allocator * | allocator,
|  | const uint8_t * | in,
|  | size_t | in_size,
|  | uint8_t * | out,
|  | size_t * | out_pos,
|  | size_t | out_size
| ) |  |

Single-call .xz Block encoder.

In contrast to the multi-call encoder initialized with lzma_block_encoder(), this function encodes also the Block Header. This is required to make it possible to write appropriate Block Header also in case the data isn't compressible, and different filter chain has to be used to encode the data in uncompressed form using uncompressed chunks of the LZMA2 filter.

When the data isn't compressible, header_size, compressed_size, and uncompressed_size are set just like when the data was compressible, but it is possible that header_size is too small to hold the filter chain specified in block->filters, because that isn't necessarily the filter chain that was actually used to encode the data. lzma_block_unpadded_size() still works normally, because it doesn't read the filters array.

Parameters

  block | Block options: block->version, block->check, and block->filters must have been initialized.
  allocator | lzma_allocator for custom allocator functions. Set to NULL to use malloc() and free().
  in | Beginning of the input buffer
  in_size | Size of the input buffer
  out | Beginning of the output buffer
  out_pos | The next byte will be written to out[*out_pos]. *out_pos is updated only if encoding succeeds.
  out_size | Size of the out buffer; the first byte into which no data is written to is out[out_size].

Returns
  - LZMA_OK: Encoding was successful.
  - LZMA_BUF_ERROR: Not enough output buffer space.
  - LZMA_UNSUPPORTED_CHECK
  - LZMA_OPTIONS_ERROR
  - LZMA_MEM_ERROR
  - LZMA_DATA_ERROR
  - LZMA_PROG_ERROR

## lzma_block_uncomp_encode()

lzma_ret lzma_block_uncomp_encode | ( | lzma_block * | block,
|  | const uint8_t * | in,
|  | size_t | in_size,
|  | uint8_t * | out,
|  | size_t * | out_pos,
|  | size_t | out_size
| ) |  |

Single-call uncompressed .xz Block encoder.

This is like lzma_block_buffer_encode() except this doesn't try to compress the data and instead encodes the data using LZMA2 uncompressed chunks. The required output buffer size can be determined with lzma_block_buffer_bound().

Since the data won't be compressed, this function ignores block->filters. This function doesn't take lzma_allocator because this function doesn't allocate any memory from the heap.