ZipArchiveEntry.Length プロパティ

定義

zip アーカイブ内のエントリの非圧縮サイズを取得します。

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

プロパティ値

Int64

zip アーカイブ内のエントリの非圧縮サイズ。

例外

プロパティの値は、エントリが変更されたため、使用できません。

次の例は、zip アーカイブからエントリを取得し、エントリのプロパティを評価する方法を示しています。 プロパティをName使用してエントリの名前を表示し、プロパティCompressedLengthLength使用してファイルが圧縮された量を計算します。

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

注釈

このプロパティは、モードが設定されている場合、またはモードが設定CreateUpdateされていてエントリが開かれている場合は取得できません。

適用対象