ZipArchiveEntry.Length 属性
定义
获取 zip 存档中的项的未压缩大小。Gets the uncompressed size of the entry in the zip archive.
public:
property long Length { long get(); };
public long Length { get; }
member this.Length : int64
Public ReadOnly Property Length As Long
属性值
在 zip 存档中的项的未压缩大小。The uncompressed size of the entry in the zip archive.
例外
由于项已修改,属性的值不可用。The value of the property is not available because the entry has been modified.
示例
下面的示例演示如何从 zip 存档中检索项,并评估项的属性。The following example shows how to retrieve entries from a zip archive, and evaluate the properties of the entries. 它使用 Name 属性显示项的名称,并使用 Length 和 CompressedLength 属性来计算文件的压缩量。It uses the Name property to display the name of the entry, and the Length and CompressedLength properties to calculate how much the file was compressed.
using System;
using System.IO;
using System.IO.Compression;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string zipPath = @"c:\example\result.zip";
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
float compressedRatio = (float)entry.CompressedLength / entry.Length;
float reductionPercentage = 100 - (compressedRatio * 100);
Console.WriteLine (string.Format("File: {0}, Compressed {1:F2}%", entry.Name, reductionPercentage));
}
}
}
}
}
Imports System.IO
Imports System.IO.Compression
Module Module1
Sub Main()
Dim zipPath As String = "c:\example\result.zip"
Using archive As ZipArchive = ZipFile.OpenRead(zipPath)
For Each entry As ZipArchiveEntry In archive.Entries
Dim compressedRatio As Single = entry.CompressedLength / entry.Length
Dim reductionPercentage As Single = 100 - (compressedRatio * 100)
Console.WriteLine(String.Format("File: {0}, Compressed {1:F2}%", entry.Name, reductionPercentage))
Next
End Using
End Sub
End Module
注解
当模式设置为 Create ,或模式设置为并且已打开该项时,无法检索此属性 Update 。This property cannot be retrieved when the mode is set to Create, or the mode is set to Update and the entry has been opened.