LZ👌 – MIT licensed C++ implementation of LZO compression/decompression algorithm
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Phillip Stephens ee8b4c29ad
Compile fixes for GCC 12 and Clang 13
1 year ago
lzokay-c Add a C wrapper for decompression 3 years ago
CMakeLists.txt Merge pull request #3 from robUx4/c-wrapper 3 years ago
Config.cmake.in Adding install commands and cmake build config file support 4 years ago
LICENSE Initial commit 4 years ago
README.md Update README.md 4 years ago
lzokay.cpp Compile fixes for GCC 12 and Clang 13 1 year ago
lzokay.hpp Compile fixes for GCC 12 and Clang 13 1 year ago
test.cpp Update test.cpp for API change 4 years ago



A minimal, C++14 implementation of the LZO compression format.


The implementation provides compression behavior similar to the lzo1x_999_compress function in lzo2 (i.e. higher compression, lower speed). The implementation is fixed to the default parameters of the original and provides no facilities for various compression "levels" or an initialization dictionary.

The decompressor is compatible with data compressed by other LZO1X implementations.


#include <lzokay.hpp>
#include <cstring>

int compress_and_decompress(const uint8_t* data, std::size_t length) {
  lzokay::EResult error;

  /* This variable and 6th parameter of compress() is optional, but may
   * be reused across multiple compression runs; avoiding repeat
   * allocation/deallocation of the work memory used by the compressor.
  lzokay::Dict<> dict;

  std::size_t estimated_size = lzokay::compress_worst_size(length);
  std::unique_ptr<uint8_t[]> compressed(new uint8_t[estimated_size]);
  std::size_t compressed_size;
  error = lzokay::compress(data, length, compressed.get(), estimated_size,
                           compressed_size, dict);
  if (error < lzokay::EResult::Success)
    return 1;

  std::unique_ptr<uint8_t[]> decompressed(new uint8_t[length]);
  std::size_t decompressed_size;
  error = lzokay::decompress(compressed.get(), compressed_size,
                             decompressed.get(), length, decompressed_size);
  if (error < lzokay::EResult::Success)
    return 1;

  if (std::memcmp(data, decompressed.get(), decompressed_size) != 0)
    return 1;

  return 0;


LZ👌 is available under the MIT License and has no external dependencies.