diff --git a/src/System.IO.Compression/src/System/IO/Compression/DeflaterZLib.cs b/src/System.IO.Compression/src/System/IO/Compression/DeflaterZLib.cs index 0aaa31dd80f4..980e5fdd4b7a 100644 --- a/src/System.IO.Compression/src/System/IO/Compression/DeflaterZLib.cs +++ b/src/System.IO.Compression/src/System/IO/Compression/DeflaterZLib.cs @@ -27,7 +27,6 @@ internal class DeflaterZLib : IDeflater #region exposed members internal DeflaterZLib() - : this(CompressionLevel.Optimal) { } @@ -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: