Skip to content

Commit

Permalink
Option #2 - use the default compression value (-1) for both Windows a…
Browse files Browse the repository at this point in the history
…nd Unix. Since we are currently planning on moving to a newer zlib version on Windows, and considering how to not even ship our own zlib, we let the current zlib version pick the best compression level.
  • Loading branch information
eerhardt committed Nov 12, 2015
1 parent fc4ecdf commit 38883e3
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions src/System.IO.Compression/src/System/IO/Compression/DeflaterZLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ internal class DeflaterZLib : IDeflater
#region exposed members

internal DeflaterZLib()

: this(CompressionLevel.Optimal)
{
}
Expand All @@ -37,39 +36,31 @@ internal DeflaterZLib(CompressionLevel compressionLevel)
ZLibNative.CompressionLevel zlibCompressionLevel;
int windowBits;
int memLevel;
ZLibNative.CompressionStrategy strategy;
ZLibNative.CompressionStrategy strategy = ZLibNative.CompressionStrategy.DefaultStrategy;

switch (compressionLevel)
{
// Note that ZLib currently exactly correspond to the optimal values.
// However, we have determined the optimal values by intependent measurements across
// a range of all possible ZLib parameters and over a set of different data.
// We stress that by using explicitly the values obtained by the measurements rather than
// ZLib defaults even if they happened to be the same.
// For ZLib 1.2.3 we have (copied from ZLibNative.cs):
// ZLibNative.CompressionLevel.DefaultCompression = 6;
// ZLibNative.Deflate_DefaultWindowBits = -15;
// ZLibNative.Deflate_DefaultMemLevel = 8;
// Since we don't know exactly which version of ZLib will be used on the machine,
// we use the ZLib DefaultCompression level for CompressionLevel.Optimal.
// This allows the current ZLib library to decide which level is the best to use.
// See the note in ZLibNative.CompressionLevel for the recommended combinations.

case CompressionLevel.Optimal:
zlibCompressionLevel = (ZLibNative.CompressionLevel)6;
windowBits = -15;
memLevel = 8;
strategy = ZLibNative.CompressionStrategy.DefaultStrategy;
zlibCompressionLevel = ZLibNative.CompressionLevel.DefaultCompression;
windowBits = ZLibNative.Deflate_DefaultWindowBits;
memLevel = ZLibNative.Deflate_DefaultMemLevel;
break;

case CompressionLevel.Fastest:
zlibCompressionLevel = ZLibNative.CompressionLevel.BestSpeed;
windowBits = -15;
memLevel = 8;
strategy = ZLibNative.CompressionStrategy.DefaultStrategy;
windowBits = ZLibNative.Deflate_DefaultWindowBits;
memLevel = ZLibNative.Deflate_DefaultMemLevel;
break;

case CompressionLevel.NoCompression:
zlibCompressionLevel = ZLibNative.CompressionLevel.NoCompression;
windowBits = -15;
windowBits = ZLibNative.Deflate_DefaultWindowBits;
memLevel = 7;
strategy = ZLibNative.CompressionStrategy.DefaultStrategy;
break;

default:
Expand Down

0 comments on commit 38883e3

Please sign in to comment.