CompressionLevel 列舉
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定值,指出壓縮作業強調速度或壓縮大小。
public enum class CompressionLevel
public enum CompressionLevel
type CompressionLevel =
Public Enum CompressionLevel
- 繼承
欄位
| 名稱 | 值 | Description |
|---|---|---|
| Optimal | 0 | 壓縮操作應在壓縮速度與輸出大小間取得最佳平衡。 |
| Fastest | 1 | 即使最終檔案未被最佳壓縮,壓縮操作也應盡快完成。 |
| NoCompression | 2 | 檔案不應進行任何壓縮。 |
| SmallestSize | 3 | 壓縮操作應產生盡可能小的輸出,即使操作完成時間較長。 |
備註
壓縮作業通常涉及壓縮速度與效能之間的權衡。 你用 CompressionLevel 列舉來表示在開發情境中哪個因素更重要:完成壓縮操作的時間,還是壓縮檔案的大小。 這些數值並不對應特定的壓縮等級;實作壓縮的物件決定如何處理這些問題。
以下 、 DeflateStream、 GZipStreamZipArchiveZipFile、 及 類別的方法ZipFileExtensions中包含一個參數compressionLevel,讓你可以指定壓縮等級:
- DeflateStream.DeflateStream(Stream, CompressionLevel)
- DeflateStream.DeflateStream(Stream, CompressionLevel, Boolean)
- GZipStream.GZipStream(Stream, CompressionLevel)
- GZipStream.GZipStream(Stream, CompressionLevel, Boolean)
- ZipArchive.CreateEntry(String, CompressionLevel)
- ZipFile.CreateFromDirectory(String, String, CompressionLevel, Boolean)
- ZipFileExtensions.CreateEntryFromFile(ZipArchive, String, String, CompressionLevel)
範例
以下範例展示了如何利用 類別 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