Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
GZIP

GZIP compression and decompression as per IETF RFC 1952. More...

Classes

class  sourcemeta::core::GZIPError
class  sourcemeta::core::GZIPStreamBuffer

Functions

auto SOURCEMETA_CORE_GZIP_EXPORT sourcemeta::core::gzip (const std::uint8_t *input, std::size_t size, int level=1) -> std::string
auto SOURCEMETA_CORE_GZIP_EXPORT sourcemeta::core::gunzip (const std::uint8_t *input, std::size_t size, std::size_t output_hint=0, std::size_t maximum_size=268435456) -> std::string

Detailed Description

GZIP compression and decompression as per IETF RFC 1952.

This functionality is included as follows:

#include <sourcemeta/core/gzip.h>

Class Documentation

◆ sourcemeta::core::GZIPError

class sourcemeta::core::GZIPError

An error that represents a GZIP compression or decompression failure

Inheritance diagram for sourcemeta::core::GZIPError:

Public Member Functions

 GZIPError (const char *message)
 Construct an error with the given message.
 GZIPError (std::string message)=delete
 GZIPError (std::string &&message)=delete
 GZIPError (std::string_view message)=delete

◆ sourcemeta::core::GZIPStreamBuffer

class sourcemeta::core::GZIPStreamBuffer

A stream buffer that performs streaming GZIP decompression (RFC 1952) over an input stream.

Inheritance diagram for sourcemeta::core::GZIPStreamBuffer:

Public Member Functions

 GZIPStreamBuffer (std::istream &compressed_stream)
 Construct a stream buffer over a compressed input stream.
 GZIPStreamBuffer (const GZIPStreamBuffer &)=delete
 GZIPStreamBuffer (GZIPStreamBuffer &&)=delete

Protected Member Functions

auto underflow () -> int_type override
 Refill the buffer with more decompressed data.

Function Documentation

◆ gunzip()

auto SOURCEMETA_CORE_GZIP_EXPORT sourcemeta::core::gunzip ( const std::uint8_t * input,
std::size_t size,
std::size_t output_hint = 0,
std::size_t maximum_size = 268435456 ) -> std::string

Decompress a GZIP compressed byte buffer (RFC 1952). An optional output size hint can be provided to avoid repeated buffer resizing. The output is bounded by a maximum size (256 MiB by default) so that a highly compressed input cannot exhaust memory, and decompressing beyond it throws. Every concatenated member is decoded and any trailing data that does not begin a new member is ignored, matching gzip(1). For example:

#include <sourcemeta/core/gzip.h>
const auto decompressed{sourcemeta::core::gunzip(
reinterpret_cast<const std::uint8_t *>(compressed.data()),
compressed.size())};
auto SOURCEMETA_CORE_GZIP_EXPORT gunzip(const std::uint8_t *input, std::size_t size, std::size_t output_hint=0, std::size_t maximum_size=268435456) -> std::string

◆ gzip()

auto SOURCEMETA_CORE_GZIP_EXPORT sourcemeta::core::gzip ( const std::uint8_t * input,
std::size_t size,
int level = 1 ) -> std::string

Compress a byte buffer using the GZIP format (RFC 1952). An optional compression level from 0 to 12 trades speed for ratio. For example:

#include <sourcemeta/core/gzip.h>
const std::string input{"hello world"};
const auto compressed{sourcemeta::core::gzip(
reinterpret_cast<const std::uint8_t *>(input.data()), input.size())};
auto SOURCEMETA_CORE_GZIP_EXPORT gzip(const std::uint8_t *input, std::size_t size, int level=1) -> std::string