Compression
Ark has a few helper classes provided to compress data. This is all contained within the
ark::compression
library.
Today, we support the following compression formats:
zstd
- A good default choice, nice balance between performance and speedlz4
- A very fast compression algorithm, but not as much size reduction as the other algorithmslzma
- A very slow compression algorithm, but also supports large size reductionsbz2
- Included for compatibility with ROS, but you should likely avoid this algorithm.
Using the library is relatively straightforward:
#include "ark/compression/compression.hh"
using ark::compression;
auto bytes = compress(CompressionType:Zstd, "Test string to compress.");
auto decoded = decompress(bytes);
You can also provide more advanced compression settings to the compress API:
auto settings = string_to_compression_settings("zstd:9");
auto bytes = compress(settings, "Test String");
This allows you to specify the compression level (for formats that support setting the level). Higher levels typically consume more CPU but offer higher compression ratios.
Framing
Note that Ark will presently append a few bytes to the end of every compressed block that helps it decompress items – this includes the decompressed size and the algorithm used.
A future update will allow you to compress/decompress data without that information.