Export (0) Print
Expand All

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)

'Declaration
Public Enumeration CompressionLevel

Member nameDescription
FastestThe compression operation should complete as quickly as possible, even if the resulting file is not optimally compressed.
NoCompressionNo compression should be performed on the file.
OptimalThe 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.

Imports System.IO
Imports System.IO.Compression

Module Module1

    Sub Main()
        Dim startPath As String = "c:\example\start" 
        Dim zipPath As String = "c:\example\result.zip"

        ZipFile.CreateFromDirectory(startPath, zipPath, CompressionLevel.Fastest, True)
    End Sub 

End Module

.NET Framework

Supported in: 4.6, 4.5

Supported in: Windows Phone 8.1
Show:
© 2015 Microsoft