CompressionLevel Enum


指定用来指示压缩操作是强调速度还是强调压缩大小的值。Specifies values that indicate whether a compression operation emphasizes speed or compression size.

public enum class CompressionLevel
public enum CompressionLevel
type CompressionLevel = 
Public Enum CompressionLevel


Fastest 1

尽快完成压缩操作,不过,无法以最佳方式压缩生成的文件。The compression operation should complete as quickly as possible, even if the resulting file is not optimally compressed.

NoCompression 2

该文件不应执行压缩。No compression should be performed on the file.

Optimal 0

以最佳方式完成压缩操作,不过,需要耗费更长的时间。The compression operation should be optimally compressed, even if the operation takes a longer time to complete.


下面的示例演示如何在使用 ZipFile 类创建 zip 存档时设置压缩级别。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\";

            ZipFile.CreateFromDirectory(startPath, zipPath, CompressionLevel.Fastest, true);
Imports System.IO
Imports System.IO.Compression

Module Module1

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

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

End Module


压缩操作通常涉及压缩速度和有效性。Compression operations usually involve a tradeoff between the speed and the effectiveness of compression. 使用 CompressionLevel 枚举来指示在开发方案中更重要的因素:完成压缩操作的时间或压缩文件的大小。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.

DeflateStreamGZipStreamZipArchiveZipFileZipFileExtensions 类的以下方法包含一个名为 "compressionLevel" 的参数,该参数可用于指定压缩级别:The following methods of the DeflateStream, GZipStream, ZipArchive, ZipFile, and ZipFileExtensions classes include a parameter named compressionLevel that lets you specify the compression level:

Applies to