Loading...
Searching...
No Matches
restinio::transforms::zlib Namespace Reference

## Namespaces

namespace | impl

## Classes

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

## Functions

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
Parameters of performing data transformation with zlib.
Definition: zlib.hpp:64
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:401

Since
  v.0.4.4

params_t | make_deflate_compress_params (int compression_level=-1)
params_t | make_deflate_decompress_params ()
params_t | make_gzip_compress_params (int compression_level=-1)
params_t | make_gzip_decompress_params ()
params_t | 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:479
restinio::transforms::zlib::gzip_compress
std::string gzip_compress(string_view_t input, int compression_level=-1)
Definition: zlib.hpp:915

It is possible to write the following:

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

Since
  v.0.4.4

std::string | transform (string_view_t input, const params_t &params)
| Do a specified zlib transformation.
std::string | deflate_compress (string_view_t input, int compression_level=-1)
std::string | deflate_decompress (string_view_t input)
std::string | gzip_compress (string_view_t input, int compression_level=-1)
std::string | 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::chunked_output_t
Tag type for chunked output response builder.
Definition: message_builders.hpp:622

Since
  v.0.4.4

template<typename Response_Output_Strategy >
body_appender_t< Response_Output_Strategy > | body_appender (response_builder_t< Response_Output_Strategy > &resp, const params_t &params)
| Create body appender with given zlib transformation parameters.
template<typename Response_Output_Strategy >
body_appender_t< Response_Output_Strategy > | 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.
template<typename Response_Output_Strategy >
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.
template<typename Response_Output_Strategy >
body_appender_t< Response_Output_Strategy > | identity_body_appender (response_builder_t< Response_Output_Strategy > &resp, int=-1)
| Create body appender with gzip transformation and a given compression level.
template<typename Extra_Data , typename Handler >
decltype(auto) | handle_body (const generic_request_t< Extra_Data > &req, Handler &&handler)
| Call a handler over a request body.

## Variables

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

Constants are defined with values provided by zlib.

Since
  v.0.4.4

constexpr int | default_window_bits = MAX_WBITS
constexpr int | default_mem_level = MAX_MEM_LEVEL
constexpr int | default_strategy = Z_DEFAULT_STRATEGY

## Function Documentation

## body_appender()

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.

Since
  v.0.4.4

Definition at line 1255 of file zlib.hpp.

## deflate_body_appender()

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.

Since
  v.0.4.4

Definition at line 1266 of file zlib.hpp.

## deflate_compress()

std::string restinio::transforms::zlib::deflate_compress | ( | string_view_t | input,
|  | int | compression_level = `-1`
| ) |  |

inline

Definition at line 903 of file zlib.hpp.

## deflate_decompress()

std::string restinio::transforms::zlib::deflate_decompress | ( | string_view_t | input | ) |

inline

Definition at line 909 of file zlib.hpp.

## gzip_body_appender()

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`
| ) |  |

inline

Create body appender with gzip transformation and a given compression level.

Since
  v.0.4.4

Definition at line 1277 of file zlib.hpp.

## gzip_compress()

std::string restinio::transforms::zlib::gzip_compress | ( | string_view_t | input,
|  | int | compression_level = `-1`
| ) |  |

inline

Definition at line 915 of file zlib.hpp.

## gzip_decompress()

std::string restinio::transforms::zlib::gzip_decompress | ( | string_view_t | input | ) |

inline

Definition at line 921 of file zlib.hpp.

## handle_body()

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.

If body is encoded with either 'deflate' or 'gzip' then it is decompressed and the handler is called.

If body is encoded with 'identity' (or not specified) the handler is called with original body.

In other cases an exception is thrown.

Template Parameters

  Handler | a function object capable to handle std::string as an argument.

Sample usage:

namespace rtz = restinio::transforms::zlib;
auto decompressed_echo_handler( restinio::request_handle_t req )
{
return
rtz::handle_body(
*req,
[&]( auto body ){
return
req->create_response()
.append_header( restinio::http_field::server, "RESTinio" )
.append_header_date_field()
.append_header(
restinio::http_field::content_type,
"text/plain; charset=utf-8" );
.set_body( std::move( body ) )
.done();
} );
}
restinio::request_handle_t
std::shared_ptr< request_t > request_handle_t
An alias for handle for incoming request without additional extra-data.
Definition: request_handler.hpp:471

Since
  v.0.4.4

Definition at line 1332 of file zlib.hpp.

## identity_body_appender()

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`
| ) |  |

inline

Create body appender with gzip transformation and a given compression level.

Since
  v.0.4.4

Definition at line 1288 of file zlib.hpp.

## make_deflate_compress_params()

params_t restinio::transforms::zlib::make_deflate_compress_params | ( | int | compression_level = `-1` | ) |

inline

Definition at line 384 of file zlib.hpp.

## make_deflate_decompress_params()

params_t restinio::transforms::zlib::make_deflate_decompress_params | ( |  | ) |

inline

Definition at line 393 of file zlib.hpp.

## make_gzip_compress_params()

params_t restinio::transforms::zlib::make_gzip_compress_params | ( | int | compression_level = `-1` | ) |

inline

Definition at line 401 of file zlib.hpp.

## make_gzip_decompress_params()

params_t restinio::transforms::zlib::make_gzip_decompress_params | ( |  | ) |

inline

Definition at line 410 of file zlib.hpp.

## make_identity_params()

params_t restinio::transforms::zlib::make_identity_params | ( |  | ) |

inline

Definition at line 418 of file zlib.hpp.

## transform()

std::string restinio::transforms::zlib::transform | ( | string_view_t | input,
|  | const params_t & | params
| ) |  |

inline

Do a specified zlib transformation.

Definition at line 893 of file zlib.hpp.

## Variable Documentation

## default_mem_level

constexpr int restinio::transforms::zlib::default_mem_level = MAX_MEM_LEVEL

constexpr

Definition at line 47 of file zlib.hpp.

## default_output_reserve_buffer_size

constexpr std::size_t restinio::transforms::zlib::default_output_reserve_buffer_size = 256 * 1024

constexpr

Default reserve buffer size for zlib transformator.

Since
  v.0.4.4

Definition at line 38 of file zlib.hpp.

## default_strategy

constexpr int restinio::transforms::zlib::default_strategy = Z_DEFAULT_STRATEGY

constexpr

Definition at line 48 of file zlib.hpp.

## default_window_bits

constexpr int restinio::transforms::zlib::default_window_bits = MAX_WBITS

constexpr

Definition at line 46 of file zlib.hpp.