Skip to content

A pure C++ implementation of a fast, small, in-memory inflate (zlib, gzip, deflate decompression)

License

Notifications You must be signed in to change notification settings

Artexety/inflatecpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Inflate++

Code Size GitHub issues GitHub license

Inflate++ is a single function call (optional), memory-to-memory decompressor for the zlib and deflate bitstream formats:

RFC 1950: ZLIB specification

RFC 1951: DEFLATE specification

RFC 1952: GZIP specification

Inflate++ is less than 1000 lines of C++ (excluding aproximatly 250 lines of the adler checksum implementation), and decompresses faster than the original zlib method.

Decompressing large raw texture file (zlib bitstream, 60,132,846 bytes compressed to 25,614,357):

Decompressor                     Time (microseconds)
zlib inflate 1.2.11              134,245 (100%)
Inflate++ (with checksum)        118,399 (91%)
Inflate++ (without checksum)     110,238 (85%)

Decompressing GZIP format archive (gzip bitstream, 147,120,395 bytes compressed to 53,625,384):

Decompressor                      Time (microseconds) 
zlib inflate 1.2.11               465,567 (100%)
Inflate++ (with checksum)         362,133 (87%)
Inflate++ (without checksum)      265,462 (65%)

Usage

First, you need to include all source files given in this repository to your project. Then include "decompressor.h" in your code and you are ready to go.

You can use the "decompressor.h" as follows:

#include <iostream>
#include <stdio.h>

#include "<dir>\decompressor.h"

int main(int argc, const char *argv[])
{
	Decompressor example_decompressor = Decompressor();

	unsigned int compressed_data_size = ...
	unsigned int max_decompressed_data_size = 200000000; // As an example
	unsigned char *compressed_data = new unsigned char[compressed_data_size];
	unsigned char *decompressed_data = new unsigned char[max_decompressed_data_size];

	// ...
	// assign values to "compressed_data"  
	// ...

	unsigned int decompressed_data_size = example_decompressor.Feed(compressed_data,
		compressed_data_size, decompressed_data, max_decompressed_data_size, true);
		// Use "true" as fifth argument of "Feed()" if you want to use the checksum
		
	if(decompressed_data_size == -1)
	{
		std::cout << "decompression error!" << std::endl;
		delete [] compressed_data;
		delete [] decompressed_data;

		return 0;
	}

	std::cout << "decompressed " << decompressed_data_size << " bytes";

	// ...
	// use the decompressed data stored in "decompressed_data"
	// ...

	return 0;
}

See example NOTE: To build the example just run build.bat in the command prompt (windows).


License

Inflate++ is developed by Artexety inspired by Mark Adlers zlib decompression. The adler checksum compution by Mark Adler. The gzip crc32 checksum by Stephen Brumme. All code is licensed under the permissive free software license (MIT). All mentions are included in the source code aswell.

About

A pure C++ implementation of a fast, small, in-memory inflate (zlib, gzip, deflate decompression)

Topics

Resources

License

Stars

Watchers

Forks

Languages