title: One library for deflate, gzip, and zlib in .net
body: <p>First, let's define some commonly confused terms:</p>
  
  <pre><code>deflate = compression_algorithm;
  zlib = header + deflate + trailer;
  gzip = header + deflate + trailer;
  </code></pre>
  
  <p>I'm looking for a library that will basically let me do the following:</p>
  
  <pre><code>if(method == "gzip"){
      Response.Filter = new CompressionLibrary.OutputStream(Response.Filter, CompressionLibrary.Formats.GZIP);
  }
  else if(method == "deflate"){
      Response.Filter = new CompressionLibrary.OutputStream(Response.Filter, CompressionLibrary.Formats.DEFLATE);
  }
  else if(method == "zlib"){
      Response.Filter = new CompressionLibrary.OutputStream(Response.Filter, CompressionLibrary.Formats.ZLIB);
  }
  </code></pre>
  
  <p>I'm looking for a way to comparably test the 3 compression formats for use on the web. I would like for the deflate compression algorthims for each format to be the same exact implementation. I've already hacked away at zlib.net to force it to give me raw deflate on command (via an "undocumented feature")...however, adding the gzip header and trailer are little out of my league.</p>
  
  <p>Anyone know of a .net library that does this?</p>
  
  <hr>
  
  <p><strong>Clarification:</strong></p>
  
  <p>HTTP 1.1's <strong>deflate</strong> compression <em>format</em> is actually the <em>zlib</em> compression format. Zlib is a wrapper around the deflate; it has a 2 byte header and a 4 byte trailer, <strong>always</strong> (when the compression methods and levels are identical).</p>
  
  <p><strong>Gzip</strong> uses the same compressed data format internally as zlib...which is deflate (raw deflate, not HTTP 1.1 deflate [which is zlib]). From my own preliminary testing, gzipped data is 11 out of 12 times larger than zlib.</p>
  
  <p><strong>deflate</strong> is a compression algorithm that is used to compress data. When there are no wrapper methods (e.g., headers or trailers) around deflated data, I call it "deflate" - perhaps I should have called it <strong>"raw deflate"</strong> instead.</p>
  
  <p>I am doing an analysis of these compression methods and their support within web browsers and need to use a single compression method for all three types.</p>