1 out of 1 rated this helpful - Rate this topic

CompressionLevel Enumeration

.NET Framework 4.5

Specifies values that indicate whether a compression operation emphasizes speed or compression size.

Namespace:  System.IO.Compression
Assembly:  System (in System.dll)
public enum CompressionLevel
Member nameDescription
Supported in .NET for Windows Store appsFastestThe compression operation should complete as quickly as possible, even if the resulting file is not optimally compressed.
Supported in .NET for Windows Store appsNoCompressionNo compression should be performed on the file.
Supported in .NET for Windows Store appsOptimalThe compression operation should be optimally compressed, even if the operation takes a longer time to complete.

Compression operations usually involve a tradeoff between the speed and the effectiveness of compression. You use the CompressionLevel enumeration to indicate which factor is more important in your development scenario: the time to complete the compression operation or the size of the compressed file. These values do not correspond to specific compression levels; the object that implements compression determines how to handle them.

The following methods of the DeflateStream, GZipStream, ZipArchive, ZipFile, and ZipFileExtensions classes include a parameter named compressionLevel that lets you specify the compression level:

The following example shows how to set the compression level when creating a zip archive by using the ZipFile class.

using System;
using System.IO;
using System.IO.Compression;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            string startPath = @"c:\example\start";
            string zipPath = @"c:\example\result.zip";

            ZipFile.CreateFromDirectory(startPath, zipPath, CompressionLevel.Fastest, true);
        }
    }
}

.NET Framework

Supported in: 4.5

.NET for Windows Store apps

Supported in: Windows 8

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.