SharpZipLib icon indicating copy to clipboard operation
SharpZipLib copied to clipboard

GZipOutputStream level 4 compresses less well (but faster) than level 3

Open MikeDimmickMnetics opened this issue 8 years ago • 1 comments

Steps to reproduce

  1. Compress a file with GZipOutputStream, calling SetLevel(4)
  2. Compress the same file with GZipOutputStream, calling SetLevel(3)

Expected behavior

The file compressed with SetLevel(4) should usually be smaller than SetLevel(3).

Actual behavior

The file compressed with SetLevel(4) is usually larger than with SetLevel(3).

Version of SharpZipLib

0.86.0.518

Obtained from (place an x between the brackets for all that apply)

  • Package installed using:
    • NuGet

The settings for level 4 in DeflaterConstants.cs are the same as in zlib, except for the compression function to use. In zlib, level 4 uses the deflateSlow function. DeflaterConstants has COMPR_FUNC[4] set to 1, which is DEFLATE_FAST. The other constants, MAX_LAZY, NICE_LENGTH and MAX_CHAIN are smaller for level 4 than for level 3, leading to worse compression in general.

MikeDimmickMnetics avatar Oct 03 '17 16:10 MikeDimmickMnetics

I have not looked in to why certain constants where used for each level. One would assume that they should be the same as in zlib.

A PR would be welcomed!

piksel avatar Sep 16 '18 13:09 piksel