This commit is contained in:
Jack Andersen 2019-07-19 18:19:30 -10:00
commit 671e2b9864
1 changed files with 8 additions and 6 deletions

View File

@ -26,22 +26,24 @@ Usage
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
/* 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 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);
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 = length;
std::size_t decompressed_size;
error = lzokay::decompress(compressed.get(), compressed_size,
decompressed.get(), decompressed_size);
decompressed.get(), length, decompressed_size);
if (error < lzokay::EResult::Success)
return 1;