LZ👌 – MIT licensed C++ implementation of LZO compression/decompression algorithm
Go to file
Jack Andersen 5c6f05a3da Remove pointless static keywords 2019-07-19 18:19:17 -10:00
CMakeLists.txt Merge branch 'cmake' of https://github.com/sfuller/lzokay 2019-06-13 14:36:31 -10:00
Config.cmake.in Adding install commands and cmake build config file support 2019-01-04 14:53:04 -07:00
LICENSE Initial commit 2018-12-23 15:43:24 -10:00
README.md Initial commit 2018-12-23 15:43:24 -10:00
lzokay.cpp Remove pointless static keywords 2019-07-19 18:19:17 -10:00
lzokay.hpp Make public API have separate input/output dest size variables 2019-06-13 14:32:25 -10:00
test.cpp Update test.cpp for API change 2019-06-13 14:40:21 -10:00

README.md

LZ👌

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

Objective

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.

Usage

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

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

  /* This variable and 5th 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 compressed_size = lzokay::compress_worst_size(length);
  std::unique_ptr<uint8_t[]> compressed(new uint8_t[compressed_size]);
  error = lzokay::compress(data, length, compressed.get(), 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 = length;
  error = lzokay::decompress(compressed.get(), compressed_size,
                             decompressed.get(), decompressed_size);
  if (error < lzokay::EResult::Success)
    return 1;

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

  return 0;
}

License

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