https://github.com/newyaroslav/brotli-hpp
Brotli header-only C++ library
https://github.com/newyaroslav/brotli-hpp
brotli brotli-compression compression cpp cpp-library cpp11 header-only http response
Last synced: 3 months ago
JSON representation
Brotli header-only C++ library
- Host: GitHub
- URL: https://github.com/newyaroslav/brotli-hpp
- Owner: NewYaroslav
- License: mit
- Created: 2021-03-20T14:03:57.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-04-07T00:47:18.000Z (about 2 years ago)
- Last Synced: 2025-04-26T14:42:24.769Z (about 1 year ago)
- Topics: brotli, brotli-compression, compression, cpp, cpp-library, cpp11, header-only, http, response
- Language: C++
- Homepage:
- Size: 5.86 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# brotli-hpp
Brotli header-only C++ library
## Usage
```cpp
// Include the specific brotli headers your code needs, for example...
#include
#include
#include
// All function calls must pass in a pointer of an
// immutable character sequence (aka a string in C) and its size
std::string data = "hello";
const char * pointer = data.data();
std::size_t size = data.size();
// Compress returns a std::string
std::string compressed_data = brotli::compress(pointer, size);
// Decompress returns std::string and decode brotli
const char * compressed_pointer = compressed_data.data();
std::string decompressed_data = brotli::decompress(compressed_pointer, compressed_data.size());
// Or like so
std::string compressed_data = brotli::compress(data);
std::string decompressed_data = brotli::decompress(compressed_data);
```
See an example project for *Code::Blocks* here: */code-blocks/*
## Dependencies
Brotli compression is implemented using the *https://github.com/google/brotli* library.
See *https://github.com/google/brotli* for more details.
To compile, include brotli library files in the project:
* *brotli/c/common/*
* *brotli/c/dec/*
* *brotli/c/enc/*
* *brotli/c/include/brotli/*
## Versioning
This library is semantically versioned using the */include/brotli/version.hpp* file.
This defines a number of macros that can be used to check the current major, minor, or patch versions, as well as the full version string.
Here's how you can check for a particular version to use specific API methods
```cpp
#if BROTLI_HPP_VERSION_MAJOR > 2
// use version 2 api
#else
// use older verion apis
#endif
```
Here's how to check the version string
```cpp
std::cout << "version: " << BROTLI_HPP_VERSION_STRING << "/n";
// => version: 1.0.0
```
And lastly, mathematically checking for a specific version:
```cpp
#if BROTLI_HPP_VERSION_CODE > 20001
// use feature provided in v2.0.1
#endif
```