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
繼承
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\result.zip";

            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\result.zip"

        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:

適用於