https://github.com/oatpp/oatpp-zlib
Module oatpp-zlib provides functionality for compressing/decompressing content with deflate and gzip. Supports both "Simple" and "Async" oatpp APIs.
https://github.com/oatpp/oatpp-zlib
cpp deflate gzip oatpp zlib
Last synced: 5 months ago
JSON representation
Module oatpp-zlib provides functionality for compressing/decompressing content with deflate and gzip. Supports both "Simple" and "Async" oatpp APIs.
- Host: GitHub
- URL: https://github.com/oatpp/oatpp-zlib
- Owner: oatpp
- License: apache-2.0
- Created: 2019-12-21T10:05:13.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-19T01:26:28.000Z (over 1 year ago)
- Last Synced: 2025-04-21T03:25:48.230Z (6 months ago)
- Topics: cpp, deflate, gzip, oatpp, zlib
- Language: C++
- Homepage: https://oatpp.io/
- Size: 61.5 KB
- Stars: 5
- Watchers: 6
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# oatpp-zlib [](https://dev.azure.com/lganzzzo/lganzzzo/_build/latest?definitionId=23&branchName=master)
Module `oatpp-zlib` provides functionality for compressing/decompressing content with `deflate` and `gzip`.
Supports both "Simple" and "Async" oatpp APIs.See more:
- [Oat++ Website](https://oatpp.io/)
- [Oat++ Github Repository](https://github.com/oatpp/oatpp)## How To Build
### Requires
- ZLib installed.
#### Install ZLib
```bash
sudo apt-get install zlib1g-dev
```### Install oatpp-zlib
Clone this repository. In the root of the repository run:
```bash
mkdir build && cd build
cmake ..
make install
```## APIs
### Automatically Compress Served Content
Configure `server::ConnectionHandler` in `AppComponent.hpp`.
```cpp
#include "oatpp-zlib/EncoderProvider.hpp"...
OATPP_CREATE_COMPONENT(std::shared_ptr, serverConnectionHandler)([] {
OATPP_COMPONENT(std::shared_ptr, router); // get Router component
/* Create HttpProcessor::Components */
auto components = std::make_shared(router);/* Add content encoders */
auto encoders = std::make_shared();encoders->add(std::make_shared());
encoders->add(std::make_shared());/* Set content encoders */
components->contentEncodingProviders = encoders;/* return HttpConnectionHandler */
return std::make_shared(components);
}());...
```Now served content will be automatically compressed and streamed to the client if the client sets `Accept-Encoding` header appropriately.
### Automatically Decompress Uploaded Content
Configure `server::ConnectionHandler` in `AppComponent.hpp`.
```cpp
#include "oatpp-zlib/EncoderProvider.hpp"
#include "oatpp/web/protocol/http/incoming/SimpleBodyDecoder.hpp"...
OATPP_CREATE_COMPONENT(std::shared_ptr, serverConnectionHandler)([] {
OATPP_COMPONENT(std::shared_ptr, router); // get Router component
/* Create HttpProcessor::Components */
auto components = std::make_shared(router);/* Add content decoders */
auto decoders = std::make_shared();decoders->add(std::make_shared());
decoders->add(std::make_shared());/* Set Body Decoder */
components->bodyDecoder = std::make_shared(decoders);/* return HttpConnectionHandler */
return std::make_shared(components);
}());...
```Now uploaded content will be automatically decompressed if the client sets `Content-Encoding` header properly.