liblzma of XZ Utils, the .xz and .lzma compression library, through C++23 modules.
English · 简体中文 · Upstream · Releases · mcpp · Index
The upstream API is unchanged. lzma_easy_encoder, lzma_stream_decoder,
lzma_code, lzma_stream, lzma_filter, lzma_ret and its enumerators are
the upstream entities of <lzma.h>, in the global namespace where upstream
declares them. The package keeps the identity of compat.xz 5.8.3, its only
implementation. The constant macros are C++ constants. Every CI run decodes
upstream's own test files with the same library.
import mcpplibs.mwrap.xz;: the functions, types and enumerators of<lzma.h>and itslzma/*.h, re-exporting the macros moduleimport mcpplibs.mwrap.xz.macros;:LZMA_PRESET_DEFAULT,LZMA_PRESET_EXTREME,LZMA_CONCATENATED,LZMA_FILTER_LZMA2,LZMA_VLI_UNKNOWN,LZMA_VERSION… inmcpplibs::mwrap::xz::macros#include <mwrap/xz/macros.hpp>:LZMA_STREAM_INIT,lzma_vli_is_valid,lzma_set_ext_size,lzma_block_header_size_decode,LZMA_VLI_C
More Modules API -> Usage and API
mcpp new pack --template mcpplibs.mwrap.xz@5.8.3
cd pack
mcpp runThe default template packs a text into an .xz stream with a CRC-64, unpacks it, and prints the sizes and the checksum.
[dependencies]
"mcpplibs.mwrap.xz" = "5.8.3"import std;
import mcpplibs.mwrap.xz;
namespace x = mcpplibs::mwrap::xz::macros;
int main() {
std::string text(10000, 'x');
std::vector<std::uint8_t> out(lzma_stream_buffer_bound(text.size()));
std::size_t size = 0;
lzma_easy_buffer_encode(x::LZMA_PRESET_DEFAULT, LZMA_CHECK_CRC64, nullptr,
reinterpret_cast<const std::uint8_t*>(text.data()), text.size(), out.data(), &size, out.size());
std::println("{} -> {} bytes", text.size(), size);
}compat.xz builds the single-threaded coders, every filter (LZMA1, LZMA2,
delta, the BCJ filters for x86, ARM, ARM64, ARM-Thumb, PowerPC, IA-64, SPARC,
RISC-V), the three checks and the .lzip decoder. It does not build the
multithreaded coders: lzma_stream_encoder_mt, lzma_stream_decoder_mt,
lzma_stream_encoder_mt_memusage and lzma_cputhreads are not exported.
A named module cannot export a macro. The constants are inline constexpr
of the same names in mcpplibs::mwrap::xz::macros. LZMA_STREAM_INIT (an
initializer) and the macros with arguments stay macros in
<mwrap/xz/macros.hpp>; two of them cast to uint32_t, so the unit imports
std.compat. A macro expands even in a qualified name. A unit that includes
<lzma.h> beside the module reads the constants through the header's macros
(docs/usage.md).
Linux, macOS and Windows CI build the modules with GCC and LLVM and run the
tests: a buffer round trip, a stream through LZMA_STREAM_INIT, a BCJ and
LZMA2 filter chain read back by the automatic decoder, the .lzma format, the
published CRC-32 and CRC-64 of 123456789, the error of garbage input, the
version against its macros, every constant against its macro, every exported
function linked, and header mixing. CI also runs:
- the export audit (tools/generate.py
--check): the module, the macro mapping, the macro header and the generated tests are regenerated from the headers as clang reads them and compared, and on macOS and Windows every name the headers declare there is exported; - upstream's 89 test files: each good file decodes, each bad file is refused (tools/run_conformance.py).
A separate job scaffolds the default template as an installed package and runs it.
Apache-2.0 for the wrapper, by mcpp-community (NOTICE). liblzma remains under the BSD Zero Clause License (upstream/xz/COPYING, COPYING.0BSD, README).