by mapbox

mapbox / gzip-hpp

Gzip header-only C++ library

145 Stars 31 Forks Last release: Not found BSD 2-Clause "Simplified" License 89 Commits 1 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Gzip C++ lib for gzip compression and decompression. Extracted from mapnik-vector-tile for light-weight modularity.

Build Status hpp-skel badge


// Include the specific gzip headers your code needs, for example...

// 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();

// Check if compressed. Can check both gzip and zlib. bool c = gzip::is_compressed(pointer, size); // false

// Compress returns a std::string std::string compressed_data = gzip::compress(pointer, size);

// Decompress returns a std::string and decodes both zlib and gzip const char * compressed_pointer = compressed_data.data(); std::string decompressed_data = gzip::decompress(compressed_pointer, compressed_data.size());

// Or like so std::string compressed_data = gzip::compress(tile->data(), tile->data.size());

// Or like so std::string value = gzip::compress(node::Buffer::Data(obj), node::Buffer::Length(obj));

// Or...etc


// Optionally include compression level
std::size_t size; // No default value, but what happens when not passed??
int level = Z_DEFAULT_COMPRESSION; // Z_DEFAULT_COMPRESSION is the default if no arg is passed

std::string compressed_data = gzip::compress(tile->data(), size, level);


// No args other than the std:string
std::string data = "hello";
std::string compressed_data = gzip::compress(data);
const char * compressed_pointer = compressed_data.data();

std::string decompressed_data = gzip::decompress(compressed_pointer, compressed_data.size());


# build test binaries

run tests

make test

You can make Release test binaries as well

BUILDTYPE=Release make
BUILDTYPE=Release make test


This library is semantically versioned using the /include/gzip/version.cpp 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 ```c++


// use version 2 api


// use older verion apis


Here's how to check the version string
std::cout << "version: " << GZIP_VERSION_STRING << "/n";
// => version: 0.2.0

And lastly, mathematically checking for a specific version: ```c++


// use feature provided in v2.0.1


We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.