CompressionLevel 列舉

定義

指定值,表示壓縮作業會強調速度還是壓縮大小。

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

欄位

Fastest 1

即使不能有效壓縮所產生的檔案,應該儘速完成壓縮作業。

NoCompression 2

不應該對檔案執行壓縮。

Optimal 0

壓縮作業應該以最佳方式平衡壓縮速度和輸出大小。

SmallestSize 3

即使作業需要較長的時間才能完成,壓縮作業也應該盡可能建立輸出。

備註

壓縮作業通常牽涉到壓縮速度和效率之間的取捨。 您可以使用 CompressionLevel 列舉來指出開發案例中哪個因素更重要:完成壓縮作業的時間或壓縮檔案的大小。 這些值不會對應到特定的壓縮層級;實作壓縮的物件會決定如何處理它們。

、、、 和 類別的下列方法 DeflateStream 包含名為 compressionLevel 的參數,可讓您指定壓縮層級: ZipFileExtensions ZipFile ZipArchive GZipStream

範例

下列範例示範如何使用 類別建立 zip 封存 ZipFile 時設定壓縮層級。

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

適用於