https://github.com/andreiamatuni/zstdpp
C++ wrapper for libzstd compression functions
https://github.com/andreiamatuni/zstdpp
compression zstandard zstd
Last synced: 13 days ago
JSON representation
C++ wrapper for libzstd compression functions
- Host: GitHub
- URL: https://github.com/andreiamatuni/zstdpp
- Owner: andreiamatuni
- License: mit
- Created: 2017-03-01T00:17:31.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2025-04-16T16:08:47.000Z (10 months ago)
- Last Synced: 2025-04-16T23:58:54.548Z (10 months ago)
- Topics: compression, zstandard, zstd
- Language: C++
- Size: 7.81 KB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ZSTDPP
A single file header only C++ convenience wrapper around the [libzstd](https://github.com/facebook/zstd) compression/decompression functions.
We use std::vector\ & std::string objects as memory containers, and pass them into the zstdpp::compress() and zstd::decompress() functions. These functions return a std::vector\, who's underlying data is either a compressed or decompressed version of the original.
There are also in-place versions of the functions, which take a preallocated memory buffer as an argument. This is useful if you're doing a lot of compression/decompression in a loop, and you want to avoid allocatins, which accept a std::string as argument, acting as a preallocated memory buffer to perform compression/decompression (instead of allocating a new buffer on each function call). This helps if you're doing a lot of compression/decompression in a loop.
# Example usage
```c++
#include
#include
#include "zstdpp.hpp"
int main() {
std::string input("this is a string that I want to compress into a smaller\n"
"string. Just to make sure there is enough data in the\n"
"compression buffer, I'm going to fill this string with a\n"
"decent amount of content. Let's hope this works.\n");
auto compressed = zstdpp::compress(input, 22);
auto decompressed = zstdpp::decompress(compressed);
}
```
# Example usage of in-place functions
```c++
#include
#include
#include "zstdpp.hpp"
int main() {
std::string input("this is a string that I want to compress into a smaller\n"
"string. Just to make sure there is enough data in the\n"
"compression buffer, I'm going to fill this string with a\n"
"decent amount of content. Let's hope this works.\n");
// we're going to use the in-place functions, so we need to allocate a buffer
std::string buffer_compress{}, buffer_decompress{};
auto compressed_size = zstdpp::inplace::compress(input, buffer_compress, 22);
auto decompressed_size = zstdpp::inplace::decompress(buffer_compress, buffer_decompress);
}
```
### For more examples, check the tests folder.