stream_buffer_encoder.c File Reference

Single-call .xz Stream encoder. More...

`#include "index.h"`

## Macros

#define | INDEX_BOUND ((1 + 1 + 2 * LZMA_VLI_BYTES_MAX + 4 + 3) & ~3)
#define | HEADERS_BOUND (2 * LZMA_STREAM_HEADER_SIZE + INDEX_BOUND)
| Stream Header, Stream Footer, and Index. More...

## Functions

size_t | lzma_stream_buffer_bound (size_t uncompressed_size)
| Calculate output buffer size for single-call Stream encoder. More...
lzma_ret | lzma_stream_buffer_encode (lzma_filter *filters, lzma_check check, const lzma_allocator *allocator, const uint8_t *in, size_t in_size, uint8_t *out, size_t *out_pos_ptr, size_t out_size)
| Single-call .xz Stream encoder. More...

## Detailed Description

Single-call .xz Stream encoder.

## Macro Definition Documentation

## INDEX_BOUND

#define INDEX_BOUND ((1 + 1 + 2 * LZMA_VLI_BYTES_MAX + 4 + 3) & ~3)

Maximum size of Index that has exactly one Record. Index Indicator + Number of Records + Record + CRC32 rounded up to the next multiple of four.

## HEADERS_BOUND

#define HEADERS_BOUND (2 * LZMA_STREAM_HEADER_SIZE + INDEX_BOUND)

Stream Header, Stream Footer, and Index.

## Function Documentation

## lzma_stream_buffer_bound()

size_t lzma_stream_buffer_bound | ( | size_t | uncompressed_size | ) |

Calculate output buffer size for single-call Stream encoder.

When trying to compress uncompressible data, the encoded size will be slightly bigger than the input data. This function calculates how much output buffer space is required to be sure that lzma_stream_buffer_encode() doesn't return LZMA_BUF_ERROR.

The calculated value is not exact, but it is guaranteed to be big enough. The actual maximum output space required may be slightly smaller (up to about 100 bytes). This should not be a problem in practice.

If the calculated maximum size doesn't fit into size_t or would make the Stream grow past LZMA_VLI_MAX (which should never happen in practice), zero is returned to indicate the error.

Note
  The limit calculated by this function applies only to single-call encoding. Multi-call encoding may (and probably will) have larger maximum expansion when encoding uncompressible data. Currently there is no function to calculate the maximum expansion of multi-call encoding.

## lzma_stream_buffer_encode()

lzma_ret lzma_stream_buffer_encode | ( | lzma_filter * | filters,
|  | lzma_check | check,
|  | 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 Stream encoder.

Parameters

  filters | Array of filters. This must be terminated with filters[n].id = LZMA_VLI_UNKNOWN. See filter.h for more information.
  check | Type of the integrity check to calculate from uncompressed data.
  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