haf / DotNetZip.Semverd

Please use System.IO.Compression! A fork of the DotNetZip project without signing with a solution that compiles cleanly. This project aims to follow semver to avoid versioning conflicts. DotNetZip is a FAST, FREE class library and toolset for manipulating zip files. Use VB, C# or any .NET language to easily create, extract, or update zip files.
Other
550 stars 235 forks source link

ZipFile vs ZipOutputStream compression difference #163

Open Kizaemon opened 5 years ago

Kizaemon commented 5 years ago

Dear Team, good job!

I wonder if you can help resolving the following issue.

When compressing same file using the ZipFile vs the ZipOutputStream, I get different resulting files, although all parameters seem to be same.

The result of ZipOutputStream seem to be smaller in size and also the throughput is smaller. Using some sparse 500 mb input file, I'm getting follwing:

ZipFile compresses to 52MB at 90 MB/sec. ZipOutputStream compresses to 47 MB at 80 MB/sec.

I would expect very similar results. What would be the reason for the difference?

Here is a piece of code for demonstration:

        byte[] ba = System.IO.File.ReadAllBytes(@"D:\hugefile.bin");

        using (var fso = new System.IO.FileStream(@"D:\test1.zip", System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None, 1024 * 1024, System.IO.FileOptions.WriteThrough))
        using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile()) {
            zip.CompressionMethod = Ionic.Zip.CompressionMethod.Deflate;
            zip.CompressionLevel = Ionic.Zlib.CompressionLevel.Level1;
            zip.Strategy = Ionic.Zlib.CompressionStrategy.Default;
            zip.ParallelDeflateThreshold = 0;
            zip.BufferSize = 1024 * 1024;
            zip.AddEntry("test1.bin", ba);
            zip.Save(fso);
        }

        using (var fso = new System.IO.FileStream(@"D:\test2.zip", System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None, 1024 * 1024, System.IO.FileOptions.WriteThrough))
        using (var zos = new Ionic.Zip.ZipOutputStream(fso, true)) {
            zos.CompressionMethod = Ionic.Zip.CompressionMethod.Deflate;
            zos.CompressionLevel = Ionic.Zlib.CompressionLevel.Level1;
            zos.Strategy = Ionic.Zlib.CompressionStrategy.Default;
            zos.ParallelDeflateThreshold = 0;
            zos.CodecBufferSize = 1024 * 1024;

            zos.PutNextEntry("test2.bin");
            zos.Write(ba, 0, ba.Length);
        }
haf commented 5 years ago

Thanks for reporting this bug/problem, and sorry about the delay in getting back to you. This is a self-service repository, where I merge PRs and where the merging of PRs causes nugets to be pushed automatically (if you bump the version number in your PR). I'll leave this issue open until someone (or yourself) fixes it.