Internal implementation of xz and its LZMA2 payload format. More...
Classes | |
| struct | block_record |
| Size metadata collected while decoding one xz block. More... | |
| class | crc64_accumulator |
| Incremental CRC-64/XZ accumulator for streamed block data. More... | |
| struct | lzma_model |
| Adaptive probability tables and state used by LZMA. More... | |
| class | range_decoder |
| One-shot LZMA range decoder. More... | |
| class | range_encoder |
| One-shot LZMA range encoder used by the deterministic literal encoder. More... | |
Functions | |
| std::uint32_t | crc32 (std::span< std::byte const > input) noexcept |
| Computes the reflected CRC-32 used by xz metadata and checks. | |
| std::uint64_t | 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 | read_variable_integer (std::span< std::byte const > input, std::size_t &position) |
| Decodes one minimal xz variable-length integer. | |
| std::size_t | check_size (std::uint8_t check_identifier) |
| Returns the number of bytes in an xz integrity check. | |
| void | update_literal_state (std::uint8_t &state) noexcept |
| Updates an LZMA state after decoding a literal. | |
| std::uint32_t | decode_length (range_decoder &decoder, lzma_model::length_model &model, std::size_t position_state) |
| Decodes one LZMA match length. | |
| void | 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 | 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 > | 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 | 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 | 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 | 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 | probability_total = 1U << 11U |
| LZMA probability-model total. | |
| constexpr std::uint32_t | probability_move_bits = 5U |
| Adaptation shift applied after every probability decision. | |
| constexpr std::uint32_t | range_top = 1U << 24U |
| Range threshold below which the arithmetic coder normalizes. | |
| constexpr std::size_t | state_count = 12U |
| Number of LZMA state-machine states. | |
| constexpr std::size_t | position_state_count = 16U |
| Maximum number of position states. | |
| constexpr std::size_t | literal_coder_count = 16U |
| Number of literal contexts retained by the supported properties. | |
| constexpr std::size_t | literal_coder_size = 0x300U |
| Probability count in one LZMA literal coder. | |
Internal implementation of xz and its LZMA2 payload format.
|
inlinenodiscard |
Returns the number of bytes in an xz integrity check.
| check_identifier | Four-bit xz check identifier. |
Definition at line 484 of file xz.hpp.
Referenced by decompress().
| 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.
| input_iterator | Single-pass byte iterator. |
| sentinel | Sentinel for first. |
| output_iterator | Destination byte iterator. |
| first | First source byte. |
| last | Sentinel past the source. |
| output | Destination iterator. |
| options | Compression level from 0 through 9. |
Definition at line 757 of file xz.hpp.
References compress_lzma_literals(), crc32(), rpnx::compression::invalid_option, rpnx::compression::compression_options::level, rpnx::compression::xz_codec::lzma_model::set_properties(), rpnx::compression::implementation::to_byte(), rpnx::compression::implementation::crc32_accumulator::update(), rpnx::compression::xz_codec::crc64_accumulator::update(), rpnx::compression::implementation::crc32_accumulator::value(), rpnx::compression::xz_codec::crc64_accumulator::value(), rpnx::compression::implementation::write_byte(), and rpnx::compression::xz.
|
inlinenodiscard |
Encodes a literal-only LZMA range-coded chunk.
| input | Source literals. |
| model | Adaptive model updated in place. |
| dictionary_position | Absolute dictionary position of the first literal. |
| previous_byte | Byte preceding the chunk, or zero at dictionary start. |
Definition at line 701 of file xz.hpp.
References rpnx::compression::xz_codec::range_encoder::encode_bit(), rpnx::compression::xz_codec::range_encoder::finish(), rpnx::compression::xz_codec::lzma_model::is_match, rpnx::compression::xz_codec::lzma_model::literal, rpnx::compression::xz_codec::lzma_model::literal_context_bits, rpnx::compression::xz_codec::lzma_model::literal_position_bits, rpnx::compression::xz_codec::lzma_model::position_bits, rpnx::compression::xz_codec::lzma_model::state, and update_literal_state().
Referenced by compress().
|
inline |
Copies one validated LZMA match into the output dictionary.
| output | Stream output and dictionary storage. |
| history_begin | Start of the current LZMA2 dictionary history. |
| dictionary_size | Declared maximum dictionary size. |
| distance | Zero-based match distance. |
| length | Number of bytes to reproduce. |
| output_limit | Absolute output-size limit. |
Definition at line 539 of file xz.hpp.
References rpnx::compression::invalid_data, rpnx::compression::output_limit_exceeded, and rpnx::compression::xz.
Referenced by decode_lzma_chunk().
|
inlinenodiscardnoexcept |
Computes the reflected CRC-32 used by xz metadata and checks.
| input | Bytes to checksum. |
Definition at line 384 of file xz.hpp.
Referenced by compress(), and decompress().
|
inlinenodiscard |
Decodes the one-byte LZMA2 dictionary-size property.
| properties | Encoded property from the xz block filter flags. |
Definition at line 730 of file xz.hpp.
References rpnx::compression::unsupported_feature, and rpnx::compression::xz.
Referenced by decompress().
|
inlinenodiscard |
Decodes one LZMA match length.
| decoder | Range decoder. |
| model | Match or repeated-match length model updated in place. |
| position_state | Current low dictionary-position state. |
Definition at line 517 of file xz.hpp.
References rpnx::compression::xz_codec::lzma_model::length_model::choice, rpnx::compression::xz_codec::lzma_model::length_model::choice2, rpnx::compression::xz_codec::range_decoder::decode_bit(), rpnx::compression::xz_codec::range_decoder::decode_tree(), rpnx::compression::xz_codec::lzma_model::length_model::high, rpnx::compression::xz_codec::lzma_model::length_model::low, and rpnx::compression::xz_codec::lzma_model::length_model::mid.
Referenced by decode_lzma_chunk().
|
inline |
Decodes one LZMA range-coded chunk into an LZMA2 dictionary.
| encoded | Complete range-coded chunk. |
| uncompressed_size | Exact number of bytes the chunk must produce. |
| model | Adaptive model retained across eligible chunks. |
| output | Stream output and dictionary storage. |
| history_begin | Start of the current LZMA2 dictionary history. |
| dictionary_size | Declared maximum dictionary size. |
| output_limit | Absolute output-size limit. |
| dictionary_position_offset | Position adjustment for chunk-local buffers. |
Definition at line 567 of file xz.hpp.
References copy_match(), rpnx::compression::xz_codec::range_decoder::decode_bit(), rpnx::compression::xz_codec::range_decoder::decode_direct(), decode_length(), rpnx::compression::xz_codec::range_decoder::decode_reverse_tree(), rpnx::compression::xz_codec::range_decoder::decode_tree(), rpnx::compression::xz_codec::lzma_model::distance_align, rpnx::compression::xz_codec::lzma_model::distance_slot, rpnx::compression::xz_codec::lzma_model::distance_special, rpnx::compression::xz_codec::range_decoder::finish(), rpnx::compression::invalid_data, rpnx::compression::xz_codec::lzma_model::is_match, rpnx::compression::xz_codec::lzma_model::is_rep, rpnx::compression::xz_codec::lzma_model::is_rep0, rpnx::compression::xz_codec::lzma_model::is_rep0_long, rpnx::compression::xz_codec::lzma_model::is_rep1, rpnx::compression::xz_codec::lzma_model::is_rep2, rpnx::compression::xz_codec::lzma_model::literal, rpnx::compression::xz_codec::lzma_model::literal_context_bits, rpnx::compression::xz_codec::lzma_model::literal_position_bits, rpnx::compression::xz_codec::lzma_model::match_length, rpnx::compression::output_limit_exceeded, rpnx::compression::xz_codec::lzma_model::position_bits, rpnx::compression::xz_codec::lzma_model::rep0, rpnx::compression::xz_codec::lzma_model::rep1, rpnx::compression::xz_codec::lzma_model::rep2, rpnx::compression::xz_codec::lzma_model::rep3, rpnx::compression::xz_codec::lzma_model::repeated_length, rpnx::compression::xz_codec::lzma_model::state, update_literal_state(), and rpnx::compression::xz.
Referenced by decompress().
| 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.
| input_iterator | Single-pass byte iterator. |
| sentinel | Sentinel for first. |
| output_iterator | Destination byte iterator. |
| first | First compressed byte. |
| last | Sentinel past the compressed input. |
| output | Destination iterator. |
| options | Output limit and concatenated-stream policy. |
Definition at line 925 of file xz.hpp.
References rpnx::compression::decompression_options::allow_concatenated_streams, check_size(), crc32(), decode_dictionary_size(), decode_lzma_chunk(), rpnx::compression::implementation::byte_reader< input_iterator, sentinel >::empty(), rpnx::compression::invalid_data, rpnx::compression::decompression_options::maximum_output_size, rpnx::compression::output_limit_exceeded, rpnx::compression::implementation::byte_reader< input_iterator, sentinel >::peek(), rpnx::compression::implementation::byte_reader< input_iterator, sentinel >::read(), read_little_endian(), read_variable_integer(), rpnx::compression::xz_codec::lzma_model::reset(), rpnx::compression::xz_codec::lzma_model::set_properties(), rpnx::compression::trailing_data, rpnx::compression::unsupported_feature, rpnx::compression::implementation::crc32_accumulator::update(), rpnx::compression::xz_codec::crc64_accumulator::update(), rpnx::compression::implementation::crc32_accumulator::value(), rpnx::compression::xz_codec::crc64_accumulator::value(), rpnx::compression::implementation::write_byte(), and rpnx::compression::xz.
|
inlinenodiscard |
Reads a fixed-width little-endian integer.
| input | Source bytes. |
| position | Current position, advanced by byte_count. |
| byte_count | Width from zero through eight bytes. |
Definition at line 435 of file xz.hpp.
References rpnx::compression::invalid_data, and rpnx::compression::xz.
Referenced by decompress().
|
inlinenodiscard |
Decodes one minimal xz variable-length integer.
| input | Source bytes. |
| position | Current position, advanced past the encoded integer. |
| compression_error | If the integer is truncated, non-minimal, or oversized. |
Definition at line 456 of file xz.hpp.
References rpnx::compression::invalid_data, and rpnx::compression::xz.
Referenced by decompress().
|
inlinenoexcept |
Updates an LZMA state after decoding a literal.
| state | State-machine value updated in place. |
Definition at line 494 of file xz.hpp.
Referenced by compress_lzma_literals(), and decode_lzma_chunk().
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
Adaptation shift applied after every probability decision.
Definition at line 31 of file xz.hpp.
Referenced by rpnx::compression::xz_codec::range_decoder::decode_bit(), and rpnx::compression::xz_codec::range_encoder::encode_bit().
|
inlineconstexpr |
LZMA probability-model total.
Definition at line 29 of file xz.hpp.
Referenced by rpnx::compression::xz_codec::range_decoder::decode_bit(), and rpnx::compression::xz_codec::range_encoder::encode_bit().
|
inlineconstexpr |
Range threshold below which the arithmetic coder normalizes.
Definition at line 33 of file xz.hpp.
Referenced by rpnx::compression::xz_codec::range_encoder::encode_bit().