zlib.hpp File Reference
`#include <restinio/impl/include_fmtlib.hpp>`
`#include <restinio/impl/string_caseless_compare.hpp>`
`#include <restinio/exception.hpp>`
`#include <restinio/string_view.hpp>`
`#include <restinio/message_builders.hpp>`
`#include <restinio/request_handler.hpp>`
`#include <zlib.h>`
`#include <string>`
`#include <cstring>`

Go to the source code of this file.

## Classes

class | restinio::transforms::zlib::params_t
| Parameters of performing data transformation with zlib. More...
class | restinio::transforms::zlib::zlib_t
| Zlib transformator. More...
class | restinio::transforms::zlib::body_appender_t< Response_Output_Strategy >
class | restinio::transforms::zlib::body_appender_base_t< Response_Output_Strategy, Descendant >
| Base class for body appenders. More...
class | restinio::transforms::zlib::x_controlled_output_body_appender_base_t< X_Controlled_Output, Descendant >
| Base class for body appenders with restinio or user controlled output. More...
class | restinio::transforms::zlib::body_appender_t< restinio_controlled_output_t >
class | restinio::transforms::zlib::body_appender_t< user_controlled_output_t >
class | restinio::transforms::zlib::body_appender_t< chunked_output_t >

## Namespaces

namespace | restinio
namespace | restinio::transforms
namespace | restinio::transforms::zlib
namespace | restinio::transforms::zlib::impl

## Functions

void | restinio::transforms::zlib::impl::ensure_is_compression_operation (params_t::operation_t op)
| Check if operation is a copression, and throw if it is not. More...
void | restinio::transforms::zlib::impl::ensure_valid_transforator (zlib_t *ztransformator)
| Check if a pointer to zlib transformator is valid. More...
std::string | restinio::transforms::zlib::impl::content_encoding_token (params_t::format_t f)
| Get token for copression format. More...
Create parameters for zlib transformators.

A set of function helping to create params_t objects ommiting some verbose deteils.

Instead of writing something like this:

params_t params{
restinio::transforms::zlib::params_t::operation_t::compress,
restinio::transforms::zlib::params_t::format_t::gzip,
-1 };
restinio::transforms::zlib::params_t::format_t::gzip
@ gzip
gzip format
restinio::transforms::zlib::params_t::operation_t::compress
@ compress
Compress the input data.

It is better to write the following:

params_t params = restinio::transforms::zlib::make_gzip_compress_params();
restinio::transforms::zlib::make_gzip_compress_params
params_t make_gzip_compress_params(int compression_level=-1)
Definition: zlib.hpp:397

Since
  v.0.4.4

params_t | restinio::transforms::zlib::make_deflate_compress_params (int compression_level=-1)
params_t | restinio::transforms::zlib::make_deflate_decompress_params ()
params_t | restinio::transforms::zlib::make_gzip_compress_params (int compression_level=-1)
params_t | restinio::transforms::zlib::make_gzip_decompress_params ()
params_t | restinio::transforms::zlib::make_identity_params ()
Helper functions for doing zlib transformation with less boilerplate.

A set of handy functions helping to perform zlib transform in one line.

Instead of writing something like this:

restinio::transforms::zlib::zlib_t z{ restinio::transforms::zlib::gzip_compress() };
z.write( data );
z.complete();
body = z.giveaway_output();
restinio::transforms::zlib::zlib_t
Zlib transformator.
Definition: zlib.hpp:475
restinio::transforms::zlib::gzip_compress
std::string gzip_compress(string_view_t input, int compression_level=-1)
Definition: zlib.hpp:900

It is possible to write the following:

body = restinio::transformators::zlib::gzip_compress( data );

Since
  v.0.4.4

std::string | restinio::transforms::zlib::transform (string_view_t input, const params_t &params)
| Do a specified zlib transformation. More...
std::string | restinio::transforms::zlib::deflate_compress (string_view_t input, int compression_level=-1)
std::string | restinio::transforms::zlib::deflate_decompress (string_view_t input)
std::string | restinio::transforms::zlib::gzip_compress (string_view_t input, int compression_level=-1)
std::string | restinio::transforms::zlib::gzip_decompress (string_view_t input)
Body appender.

Helper class for setting the body of response_builder_t<chunked_output_t>.

Sample usage:

namespace rtz = restinio::transforms::zlib;
auto resp = req->create_response<chunked_output_t>();
resp.append_header( restinio::http_field::server, "RESTinio" )
.append_header_date_field()
.append_header( restinio::http_field::content_type, "text/plain; charset=utf-8" );
auto ba = rtz::gzip_body_appender( resp );
ba.append( some_data );
ba.append( some_more_data );
ba.make_chunk(); // Flush copressed data and creates a chunk with it.
ba.flush(); // Send currently prepared chunks to client
// ...
// Copress the data and creates a chunk with it.
ba.make_chunk( even_more_data );
ba.flush(); // Send currently prepared chunks to client
// ...
ba.append( yet_even_more_data );
ba.append( last_data );
ba.complete(); // Creates last chunk, but doesn't send it to client.
ba.flush(); // Send chunk created by complete() call
// ...
resp.done();
restinio::transforms::zlib
Definition: zlib.hpp:34
restinio::transforms::zlib::gzip_body_appender
body_appender_t< Response_Output_Strategy > gzip_body_appender(response_builder_t< Response_Output_Strategy > &resp, int compression_level=-1)
Create body appender with gzip transformation and a given compression level.
Definition: zlib.hpp:1262

Since
  v.0.4.4

template<typename Response_Output_Strategy >
body_appender_t< Response_Output_Strategy > | restinio::transforms::zlib::body_appender (response_builder_t< Response_Output_Strategy > &resp, const params_t &params)
| Create body appender with given zlib transformation parameters. More...
template<typename Response_Output_Strategy >
body_appender_t< Response_Output_Strategy > | restinio::transforms::zlib::deflate_body_appender (response_builder_t< Response_Output_Strategy > &resp, int compression_level=-1)
| Create body appender with deflate transformation and a given compression level. More...
template<typename Response_Output_Strategy >
body_appender_t< Response_Output_Strategy > | restinio::transforms::zlib::gzip_body_appender (response_builder_t< Response_Output_Strategy > &resp, int compression_level=-1)
| Create body appender with gzip transformation and a given compression level. More...
template<typename Response_Output_Strategy >
body_appender_t< Response_Output_Strategy > | restinio::transforms::zlib::identity_body_appender (response_builder_t< Response_Output_Strategy > &resp, int=-1)
| Create body appender with gzip transformation and a given compression level. More...
template<typename Extra_Data , typename Handler >
decltype(auto) | restinio::transforms::zlib::handle_body (const generic_request_t< Extra_Data > &req, Handler &&handler)
| Call a handler over a request body. More...

## Variables

constexpr std::size_t | restinio::transforms::zlib::default_output_reserve_buffer_size = 256 * 1024
| Default reserve buffer size for zlib transformator. More...
Default values for zlib tuning parameters.

Constants are defined with values provided by zlib.

Since
  v.0.4.4

constexpr int | restinio::transforms::zlib::default_window_bits = MAX_WBITS
constexpr int | restinio::transforms::zlib::default_mem_level = MAX_MEM_LEVEL
constexpr int | restinio::transforms::zlib::default_strategy = Z_DEFAULT_STRATEGY