RPNX::Compress
Self-contained C++20 compression and ZIP library
 
Loading...
Searching...
No Matches
xz.hpp File Reference

Native xz container, LZMA2, and range-coding implementation. More...

#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iterator>
#include <limits>
#include <optional>
#include <span>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
#include <rpnx/compression/implementation/io.hpp>

Go to the source code of this file.

Classes

struct  rpnx::compression::xz_codec::block_record
 Size metadata collected while decoding one xz block. More...
 
struct  rpnx::compression::xz_codec::lzma_model
 Adaptive probability tables and state used by LZMA. More...
 
struct  rpnx::compression::xz_codec::lzma_model::length_model
 Probability tables for the three LZMA match-length ranges. More...
 
class  rpnx::compression::xz_codec::range_decoder
 One-shot LZMA range decoder. More...
 
class  rpnx::compression::xz_codec::range_encoder
 One-shot LZMA range encoder used by the deterministic literal encoder. More...
 
class  rpnx::compression::xz_codec::crc64_accumulator
 Incremental CRC-64/XZ accumulator for streamed block data. More...
 

Namespaces

namespace  rpnx::compression
 Facilities for creating and decoding supported compressed streams.
 
namespace  rpnx::compression::xz_codec
 Internal implementation of xz and its LZMA2 payload format.
 

Functions

std::uint32_t rpnx::compression::xz_codec::crc32 (std::span< std::byte const > input) noexcept
 Computes the reflected CRC-32 used by xz metadata and checks.
 
std::uint64_t rpnx::compression::xz_codec::read_little_endian (std::span< std::byte const > input, std::size_t &position, std::uint8_t byte_count)
 Reads a fixed-width little-endian integer.
 
std::uint64_t rpnx::compression::xz_codec::read_variable_integer (std::span< std::byte const > input, std::size_t &position)
 Decodes one minimal xz variable-length integer.
 
std::size_t rpnx::compression::xz_codec::check_size (std::uint8_t check_identifier)
 Returns the number of bytes in an xz integrity check.
 
void rpnx::compression::xz_codec::update_literal_state (std::uint8_t &state) noexcept
 Updates an LZMA state after decoding a literal.
 
std::uint32_t rpnx::compression::xz_codec::decode_length (range_decoder &decoder, lzma_model::length_model &model, std::size_t position_state)
 Decodes one LZMA match length.
 
void rpnx::compression::xz_codec::copy_match (std::vector< std::byte > &output, std::size_t history_begin, std::uint32_t dictionary_size, std::uint32_t distance, std::uint32_t length, std::size_t output_limit)
 Copies one validated LZMA match into the output dictionary.
 
void rpnx::compression::xz_codec::decode_lzma_chunk (std::span< std::byte const > encoded, std::size_t uncompressed_size, lzma_model &model, std::vector< std::byte > &output, std::size_t history_begin, std::uint32_t dictionary_size, std::size_t output_limit, std::size_t dictionary_position_offset=0U)
 Decodes one LZMA range-coded chunk into an LZMA2 dictionary.
 
std::vector< std::byte > rpnx::compression::xz_codec::compress_lzma_literals (std::span< std::byte const > input, lzma_model &model, std::size_t dictionary_position, std::uint8_t previous_byte)
 Encodes a literal-only LZMA range-coded chunk.
 
std::uint32_t rpnx::compression::xz_codec::decode_dictionary_size (std::uint8_t properties)
 Decodes the one-byte LZMA2 dictionary-size property.
 
template<std::input_iterator input_iterator, std::sentinel_for< input_iterator > sentinel, typename output_iterator>
output_iterator rpnx::compression::xz_codec::compress (input_iterator first, sentinel last, output_iterator output, compression_options const &options)
 Compresses an iterator range as an xz stream containing LZMA2.
 
template<std::input_iterator input_iterator, std::sentinel_for< input_iterator > sentinel, typename output_iterator>
output_iterator rpnx::compression::xz_codec::decompress (input_iterator first, sentinel last, output_iterator output, decompression_options const &options)
 Decompresses one or more xz streams containing LZMA2.
 

Variables

constexpr std::uint32_t rpnx::compression::xz_codec::probability_total = 1U << 11U
 LZMA probability-model total.
 
constexpr std::uint32_t rpnx::compression::xz_codec::probability_move_bits = 5U
 Adaptation shift applied after every probability decision.
 
constexpr std::uint32_t rpnx::compression::xz_codec::range_top = 1U << 24U
 Range threshold below which the arithmetic coder normalizes.
 
constexpr std::size_t rpnx::compression::xz_codec::state_count = 12U
 Number of LZMA state-machine states.
 
constexpr std::size_t rpnx::compression::xz_codec::position_state_count = 16U
 Maximum number of position states.
 
constexpr std::size_t rpnx::compression::xz_codec::literal_coder_count = 16U
 Number of literal contexts retained by the supported properties.
 
constexpr std::size_t rpnx::compression::xz_codec::literal_coder_size = 0x300U
 Probability count in one LZMA literal coder.
 

Detailed Description

Native xz container, LZMA2, and range-coding implementation.

Definition in file xz.hpp.