ZipArchiveEntry.Length Proprietà

Definizione

Ottiene la dimensione non compressa della voce nell'archivio ZIP.

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

Valore della proprietà

Dimensione non compressa della voce nell'archivio ZIP.

Eccezioni

Il valore della proprietà non è disponibile poiché la voce è stata modificata.

Esempio

Nell'esempio seguente viene illustrato come recuperare le voci da un archivio ZIP e valutare le proprietà delle voci. Usa la Name proprietà per visualizzare il nome della voce e le Length proprietà e CompressedLength per calcolare la quantità di compressione del file.

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

Commenti

Questa proprietà non può essere recuperata quando la modalità è impostata su Createoppure la modalità è impostata su Update e la voce è stata aperta.

Si applica a