ZipArchiveEntry.CompressedLength Vlastnost

Definice

Získá komprimovanou velikost položky v archivu zip.

public:
 property long CompressedLength { long get(); };
public long CompressedLength { get; }
member this.CompressedLength : int64
Public ReadOnly Property CompressedLength As Long

Hodnota vlastnosti

Komprimovaná velikost položky v archivu zip.

Výjimky

Hodnota vlastnosti není k dispozici, protože položka byla změněna.

Příklady

Následující příklad ukazuje, jak načíst položky v archivu zip a vyhodnotit vlastnosti položek. Vlastnost používá Name k zobrazení názvu položky a Length vlastnosti a CompressedLength k výpočtu míry komprimace souboru.

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

Poznámky

Tuto vlastnost nelze načíst, pokud je režim nastaven na Create, nebo je režim nastaven na Update a položka byla otevřena.

Platí pro