Compress
RPNX compression library
 
Loading...
Searching...
No Matches
RPNX Compress

RPNX Compress is a portable C++20 compression library with STL-style iterator algorithms, deterministic encoders, bounded decompression, and validated ZIP archive handling.

Supported formats

Format Compression Decompression Concatenated members
Raw DEFLATE Yes Yes Optional
zlib Yes Yes Optional
gzip Yes Yes Optional
bzip2 Yes Yes Optional
xz/LZMA2 Yes Yes Optional
Zstandard Yes Yes Optional
LZ4 frame Yes Yes Optional
ZIP32 archives Yes Yes Not applicable

ZIP supports stored and DEFLATE members, including validated data descriptors. ZIP64, encryption, and multi-disk archives are rejected explicitly rather than processed partially. The xz decoder supports the common single LZMA2 filter chain; optional BCJ and delta filter chains are rejected. Zstandard and LZ4 frames that require an external dictionary are likewise rejected because this API has no dictionary parameter.

For fixed input, options, and library version, each encoder produces byte-identical output. gzip timestamps and ZIP timestamps and host metadata are normalized. Applications requiring reproducible artifacts across build environments should pin the RPNX Compress version as part of their build workspace.

Primary template API

#include <rpnx/compression/compression.hpp>
#include <cstddef>
#include <iterator>
#include <vector>
std::vector<std::byte> input = /* ... */;
std::vector<std::byte> encoded;
input.begin(),
input.end(),
std::back_inserter(encoded));
std::vector<std::byte> decoded;
encoded.begin(),
encoded.end(),
std::back_inserter(decoded));
std::vector< std::byte > compress(format stream_format, std::span< std::byte const > input, compression_options const &options)
Definition compression.cpp:107
std::vector< std::byte > decompress(format stream_format, std::span< std::byte const > input, decompression_options const &options)
Definition compression.cpp:114

Input ranges may contain std::byte or one-byte integral values. Output iterators may accept std::byte or std::uint8_t. Both algorithms return the advanced output iterator. decompression_options::maximum_output_size limits the number of bytes written by decompression.

Compile-time format selection instantiates header-native codec paths directly. Runtime-format iterator overloads remain available when the format is selected dynamically.

Non-template span API

Consumers that prefer shorter compile times can use the compiled overloads:

std::vector<std::byte> encoded = rpnx::compression::compress(
rpnx::compression::format::gzip,
std::span<std::byte const>(input));
std::vector<std::byte> output_storage(input.size());
std::size_t const written = rpnx::compression::decompress(
rpnx::compression::format::gzip,
std::span<std::byte const>(encoded),
std::span<std::byte>(output_storage));
output_storage.resize(written);

Both allocating and caller-owned span forms are non-template functions. The compiled functions adapt their spans to the iterator algorithms; they do not provide a second codec implementation. The caller-owned form reports error_code::insufficient_output_space when its destination is exhausted.

ZIP uses the corresponding create_zip and extract_zip iterator algorithms from <rpnx/compression/zip.hpp>. Extracted paths are validated as relative, forward-slash-separated archive paths; absolute paths, drive paths, backslashes, and .. components are rejected.

Streaming and storage model

The codec implementations consume single-pass input iterators and write each completed byte through the supplied output iterator. They do not materialize a complete source or result. Storage retained by an algorithm is bounded or required by its transform: DEFLATE history and match-search blocks, LZ4 and Zstandard blocks and histories, bzip2 BWT blocks, and xz LZMA2 chunks and dictionaries. ZIP creation retains only central-directory metadata. ZIP extraction materializes the archive because the trailing central directory points backward to member headers.

Dependencies

Raw DEFLATE, zlib, gzip, bzip2, xz/LZMA2, Zstandard, LZ4 frame, CRC-32, Adler-32, XXH32, XXH64, and ZIP are self-contained. The library contains no vendored third-party codec sources and links no system compression packages. Third-party implementations may be used externally for interoperability verification only. CMake never downloads dependencies. The installed package exports the target RPNX::compression.

cbuild/csetup workflow

The development workspace is intentionally separate from the source tree:

cd build
csetup detect-toolchains
cbuild test -c Debug -t compress
cbuild test -c DebugASAN -t compress
cbuild build -c Release -t compress

The workspace selects C++20; the root CMake project does not set a global C++ standard or compiler flags. A consuming CMake project can link the build-tree or installed package as follows:

find_package(RPNXCompress REQUIRED)
target_link_libraries(application PRIVATE RPNX::compression)