Is it possible to set compression level when using .NET's GZipStream
to compress a stream? It seems that Ionic Zip has a constructor for this, but I would rather not use a library just to get this feature.
As of .NET 4.5, the CompressionLevel
enum has been added to a couple constructors for GZipStream
.
The options are:
CompressionLevel.Optimal = 0
CompressionLevel.Fastest = 1
CompressionLevel.NoCompression = 2
So, you can now create a GZipStream
by passing a CompressionLevel
which determines how much to compress the data.
using (GZipStream compressionStream = new GZipStream(stream, CompressionLevel.Optimal))
{
// ...
}
More information is available in the GZipStream
documentation or the CompressionLevel
documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With