CompressionLevel 枚举


指定表明是否压缩操作重点介绍速度或压缩大小的值。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.

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