Defines | Functions

/tmp/buildd/xz-utils-5.0.0/src/liblzma/common/block_buffer_encoder.c File Reference

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

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

Defines

#define HEADERS_BOUND

Functions

static lzma_vli lzma2_bound (lzma_vli uncompressed_size)
size_t lzma_block_buffer_bound (size_t uncompressed_size)
 Calculate maximum output size for single-call Block encoding.
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, lzma_allocator *allocator, const uint8_t *in, size_t in_size, uint8_t *out, size_t *out_pos, size_t out_size)
lzma_ret lzma_block_buffer_encode (lzma_block *block, 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.

Detailed Description

Single-call .xz Block encoder.


Define Documentation

#define HEADERS_BOUND
Value:
((1 + 1 + 2 * LZMA_VLI_BYTES_MAX + 3 + 4 \
                + LZMA_CHECK_SIZE_MAX + 3) & ~3)

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.

Referenced by lzma_block_buffer_bound().


Function Documentation

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().

References HEADERS_BOUND, and LZMA_VLI_C.

Referenced by lzma_stream_buffer_bound().

lzma_ret lzma_block_buffer_encode ( lzma_block block,
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_OPTIONS_ERROR
  • LZMA_MEM_ERROR
  • LZMA_DATA_ERROR
  • LZMA_PROG_ERROR

References lzma_check_state::buffer, check, LZMA_BUF_ERROR, lzma_check_finish(), lzma_check_init(), lzma_check_size(), lzma_check_update(), LZMA_OK, and return_if_error.

Referenced by lzma_stream_buffer_encode().