lzokay/README.md

63 lines
1.8 KiB
Markdown
Raw Permalink Normal View History

2018-12-23 17:43:24 -08:00
LZ👌
===
A minimal, C++14 implementation of the
[LZO compression format](http://www.oberhumer.com/opensource/lzo/).
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
-----
```cpp
#include <lzokay.hpp>
#include <cstring>
int compress_and_decompress(const uint8_t* data, std::size_t length) {
lzokay::EResult error;
2019-07-13 14:35:06 -07:00
/* This variable and 6th parameter of compress() is optional, but may
2018-12-23 17:43:24 -08:00
* be reused across multiple compression runs; avoiding repeat
* allocation/deallocation of the work memory used by the compressor.
*/
lzokay::Dict<> dict;
2019-07-13 14:33:55 -07:00
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);
2018-12-23 17:43:24 -08:00
if (error < lzokay::EResult::Success)
return 1;
std::unique_ptr<uint8_t[]> decompressed(new uint8_t[length]);
2019-07-13 14:33:55 -07:00
std::size_t decompressed_size;
2018-12-23 17:43:24 -08:00
error = lzokay::decompress(compressed.get(), compressed_size,
2019-07-13 14:33:55 -07:00
decompressed.get(), length, decompressed_size);
2018-12-23 17:43:24 -08:00
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](https://github.com/jackoalan/lzokay/blob/master/LICENSE)
and has no external dependencies.