Best .NET Framework compression class?

Related searches

Yes, I know GZipStream or DeflateStream is the common ones in .NET Framework which handle compression/decompression.

I wish to have compress/decompress functions in my program, but

  1. I wish a .NET Framework C# one, not a 3rd party open source. I can't use because of those copyright restrictions in my program.

  2. GZipStream and DeflateStream are not so good. for e.g., GZipStream compress a file to 480KB while 7Zip compress the same file to the size of 57KB.

Does Microsoft have other good compression methods???

Thanks

GZipStream and DeflateStream are specifically intended for compressed streams, not general compression of files for storage.

Other than those classes, compression is not built into .NET. If you want high-quality compression you will have to go to a third party library. Check out http://www.7-zip.org/sdk.html for an open-source 7zip library.

Best 20 NuGet compression Packages, K4os.Compression.LZ4.Streams. Port of LZ4 compression algorithm for .NET NET Class Library (64-bit) for SSH/SFTP, FTP, CAdES, XAdES, REST, POP3, SMTP, Supported Platforms: • NETStandard • NETFramework Load, save, export,� The System.IO.Compression namespace contains classes that provide basic compression and decompression services for streams.

There is a managed wrapper for 7zip. The license is LGPL so you can use it in closed source projects. I do not know if this fits your license requirements as you did not state them.

http://sevenzipsharp.codeplex.com/

How to: Compress and extract files, NET Framework 4.5, the DeflateStream class uses the zlib library for passes to determine the best method for compressing entire files or large blocks of data. The gzip data format uses the same algorithm as the DeflateStream class, but can be extended to use other compression formats. The format can be readily implemented in a manner not covered by patents. Starting with the .NET Framework 4.5, the DeflateStream class uses the zlib library for compression. As a result, it provides a better compression algorithm and, in most cases, a smaller compressed file than it provides in earlier versions of the .NET Framework.

I don't have any statistics regarding compression rates, but I'd been using the SharpZipLib library for years with much success.

GZipStream Class (System.IO.Compression), NET offering the fastest LZF4, DEFLATE, ZLIB & GZIP implementations and LZMA DotNetCompression is a real-time compression library in C# that provides Mac, Windows Phone, Xbox, Silverlight, Mono and as Portable Class Libraries. .Net Core is a lightweight and cross-platform version of the DotNet framework and the wonderful thing is that Developers required the same expertise to code with .Net Core as .Net Framework. With Every new Update, new features are added that help developers deploy high-performance & highly scalable applications using less Code.

you can also use the open source ZLib (http://www.zlib.net/) with PInvoke, or use a wrapper for it (I've used zlib.net - http://www.componentace.com/zlib_.NET.htm - but I believe it had some bugs). it's less convenient than managed libraries, but more efficient than DeflateStream/GZipStream (which are the same except for an extra CRC in GZipStream).

Fastest compression algorithms for .NET, NET framework version 4 and earlier. This means that I couldn't make use of the new zip compression classes introduced in .NET 4.5 (see� Examples. This example shows how to create and extract a zip archive by using the ZipFile class. It compresses the contents of a folder into a zip archive, and then extracts that content to a new folder.

Well, I try to compress like recursive data, is funny. Check my example:

private byte[] CompressWithLevels(byte[] data)
{
    using(MemoryStream ms = new MemoryStream())
    {
        using(GZipStream gz = new GZipStream(ms, CompressionMode.Compress))
        {
            gz.Write(data, 0, data.Length);
            return ms.ToArray();
        }
    }
}

Now, I try to Compress a file too big, for example:

string path = @"c:\test.bin";
byte[] buffer = File.ReadAllBytes(path);
byte[] level1 = CompressWithLevels(buffer);
byte[] level2 = CompressWithLevels(level1);

Check the size of buffer, level1 and level2. buffer size is 77683, level1 = 57354 and level2 = 8202...

buffer is 100%, then: 57354 is 73,83% 8202 is 10,55% so funny.

C#, The Framework Class Library or FCL provides the system functionality in the .NET Framework as it has various classes, data types, interfaces, etc. to perform multiple functions and build different types of applications such as desktop applications, web applications, mobile applications, etc.

System.IO.Compression; System.IO.Compression.ZipFile; If you're using .NET Framework, add references to these two libraries to your project: System.IO.Compression; System.IO.Compression.FileSystem; Example 1: Create and extract a .zip file. The following example shows how to create and extract a compressed .zip file by using the ZipFile class.

If you reference the System.IO.Compression.FileSystem assembly in your project, you can access four extension methods (from the ZipFileExtensions class) for the ZipArchive class: CreateEntryFromFile(ZipArchive, String, String), CreateEntryFromFile(ZipArchive, String, String, CompressionLevel), ExtractToDirectory(ZipArchive, String), and

Brotli is a generic-purpose lossless compression algorithm that compresses data using a combination of a modern variant of the LZ77 algorithm, Huffman coding and 2nd order context modeling, with a compression ratio comparable to the best currently available general-purpose compression methods.

Comments
  • Thanks for all your replies. Can I ask whether DeflateStream is using Huffman coding?
  • Both DeflateStream and GZipStream use a combination of the LZ77 algorithm and Huffman coding (see msdn.microsoft.com/en-us/library/… and msdn.microsoft.com/en-us/library/…). Deflate is the pure compression algorithm, while GZipStream includes a CRC checksum and could be extended by writing different compression algorithms (The current .net framework just implements that one compression algorithm).
  • The web page states that "LZMA SDK is placed in the public domain" that should mean that it is free to use however you like, doesn´t it?
  • Dave put it in the right direction, but Stefan gave the link to the ready to use .Net implementation of the 7zip algorithm (which is lzma).
  • Absolutely, free to all. The OP says he doesn't want "3rd party open source." If cost is not the concern, I'm not sure what is.
  • Just wanted to share with future people; C# has the ZipArchive class. If used with optimal compression option you might also get good results.