CompressionLevel 枚举
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定用来指示压缩操作是强调速度还是强调压缩大小的值。
public enum class CompressionLevel
public enum CompressionLevel
type CompressionLevel =
Public Enum CompressionLevel
- 继承
名称 | 值 | 说明 |
---|---|---|
Fastest | 1 | 即使结果文件未可选择性地压缩,压缩操作也应尽快完成。 |
NoCompression | 2 | 该文件不应执行压缩。 |
Optimal | 0 | 压缩操作应以最佳方式平衡压缩速度和输出大小。 |
SmallestSize | 3 | 压缩操作应创建尽可能小的输出,即使该操作需要更长的时间才能完成。 |
压缩操作通常涉及压缩速度和有效性之间的权衡。 使用 CompressionLevel 枚举来指示哪个因素在开发方案中更重要:完成压缩操作的时间或压缩文件的大小。 这些值与特定的压缩级别不对应;实现压缩的 对象确定如何处理它们。
、、、 ZipArchive和 类的DeflateStream以下方法包括一个名为 compressionLevel
的参数,可用于指定压缩级别:ZipFileExtensionsZipFileGZipStream
DeflateStream.DeflateStream(Stream, CompressionLevel, Boolean)
ZipFile.CreateFromDirectory(String, String, CompressionLevel, Boolean)
ZipFileExtensions.CreateEntryFromFile(ZipArchive, String, String, CompressionLevel)
以下示例演示如何在使用 ZipFile 类创建 zip 存档时设置压缩级别。
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
产品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |