This project is read-only.
Project Description
Deflater is a HTTP Compression Library, supporting Deflate (RFC 1950, RFC 1951) and GZip (RFC 1952). It is designed to encode and compress HTML content at once.

HTTP Content Compression

This compressor is designed to act as a high performance and high throughput content compressor for dynamic generated HTML content.

Speed up HTTP Compression

Encoding and compression in one step

The method Deflate.Write(string text, int offset, int length, Encoding encoding) does the encoding (currently UTF-8) and compression in one step. It writes the encoded bytes directly into the internal compression buffer. This saves all the string concatenation that a normal compressor needs. In contrast a ISAPI filter compresses the already written and concatenated HTML text. Normal HTML Text writers have a StringBuilder inside, allocation a lot of strings during the Append() function calls. That produces a lot of memory garbage.

Using the output buffer

The output buffer is passed to the StoreData delegate. The store data delegate can process the data (e.g. send it directly as a chunk) without additional buffer allocations.

Using HTML optimized compression settings

A HTML deflater can be optimized for HTML and nothing else.

Data Compression Code Sample

            DeflaterConfig config = new DeflaterConfig();
            config.OutputBufferSize = 64000;
            config.Format = DeflaterConfig.StreamFormat.GZIP;
            config.StoreDataDelegate = ...  // A delegate witch stores the processed data when the output buffer is full 
            config.StoreDataContext = ...  // A object that is passed to the StoreDataDelegate
            config.FastCompression = true;

            Deflater deflater = new Deflater();
            deflater.Write(data, 0, data.Length);

Supported Compression Formats

  • ZLib - Deflate compressed data in a ZLib envelope as defined in RFC 1950
  • Deflate - raw Deflate compressed data as defined in RFC 1951
  • GZip - Deflate compressed Data in a GZip envelope as defined in RFC 1952


This library is a heavily modified version of the SharpZipLib deflater Copyright holders are:
Copyright (C) 2001 Mike Krueger
Copyright (C) 2004 John Reilly
Copyright (C) 2010 Thomas Maierhofer


The library is licensed by the "GNU General Public License Version 2" (GPLv2)
As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend/ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.

Last edited Mar 11, 2010 at 1:49 PM by ThomasMaierhofer, version 9