C++ code gems: a DEFLATE implementation (RFC1951)

edited August 2009 in KLayout Development

When developing the OASIS reader, I encountered a problem with an OASIS specific feature, namely compressed blocks being embedded in OASIS files.

The OASIS specification states that any OASIS file may use internal compression using embedded CBLOCK records. These records specify binary data which must be decompressed on the fly while reading and decoded as normal OASIS record sequences. As the main compression standard, DEFLATE is proposed. DEFLATE is being used by "gzip" and an implementation is available with the ZLIB library.

However, if the whole file is compressed itself, the ZLIB is no solution, because it can uncompress binary data from a regular file, not from a ZLIB uncompressed output stream (except by buffering the compressed data at the cost of higher memory usage).

To overcome that limitation, I implemented the RFC1951 specification once more, this time for use on the input data stream delivered by the ZLIB. The implementation can be found in tlDeflate.h and tlDeflate.cc.

My personal opinion is that this implementation is easier to read than the ZLIB source code. It's performance is comparable to that of the ZLIB.

Sign In or Register to comment.