tinf - tiny inflate library
Version 1.2.1
Copyright (c) 2003-2019 Joergen Ibsen
About
tinf is a small library implementing the decompression algorithm for the deflate compressed data format (called 'inflate'). Deflate compression is used in e.g. zlib, gzip, zip, and png.
I wrote it because I needed a small in-memory zlib decompressor for a self- extracting archive, and the zlib library added 15k to my program. The tinf code added only 2k.
Naturally the size difference is insignificant in most cases. Also, the zlib library has many more features, is well-tested, and mostly faster. But if you have a project that calls for a small and simple deflate decompressor, give it a try :-)
Usage
The include file src/tinf.h
contains documentation in the form of
doxygen comments.
Wrappers for decompressing zlib and gzip data in memory are supplied.
tgunzip, an example command-line gzip decompressor in C, is included.
tinf uses CMake to generate build systems. To create one for the tools on your platform, and build tinf, use something along the lines of:
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --config Release
You can also compile the source files and link them into your project. CMake just provides an easy way to build and test across various platforms and toolsets.
Notes
tinf requires int to be at least 32-bit.
The inflate algorithm and data format are from 'DEFLATE Compressed Data Format Specification version 1.3' (RFC 1951).
The zlib data format is from 'ZLIB Compressed Data Format Specification version 3.3' (RFC 1950).
The gzip data format is from 'GZIP file format specification version 4.3' (RFC 1952).
The original version of tinf assumed it was given valid compressed data, and that there was sufficient space for the decompressed data. If code size is of the utmost importance, and you are absolutely sure you can trust the compressed data, you may want to check out tinf 1.1.0 (last release without security checks).
Ideas for future versions:
- Memory for the
tinf_data
object should be passed, to avoid using more than 1k of stack space - Wrappers for unpacking zip archives and png images
- Blocking of some sort, so everything does not have to be in memory
- Optional table-based Huffman decoder
- Small compressor using fixed Huffman trees
Related Projects
- puff (in the contrib folder of zlib)
- tinfl (part of miniz)
- uzlib
- gdunzip (GDScript)
- TinyDeflate (C++)
- tiny-inflate (JavaScript)
- tinflate (unrelated to this project)
- The Wikipedia page for deflate has a list of implementations
License
This projected is licensed under the zlib License (Zlib).