Class ArchiveEntry

Class ArchiveEntry

Namespace: Aspose.Zip
Assembly: Aspose.Zip.dll (25.1.0)

アーカイブ内の単一ファイルを表します。

public abstract class ArchiveEntry : IArchiveFileEntry

継承

objectArchiveEntry

派生

ArchiveEntryEncrypted, ArchiveEntryPlain

実装

IArchiveFileEntry

継承メンバー

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

備考

Aspose.Zip.ArchiveEntry インスタンスを Aspose.Zip.ArchiveEntryEncrypted にキャストして、エントリが暗号化されているかどうかを判断します。

コンストラクタ

ArchiveEntry(string, CompressionSettings, Func<stream>, FileAttributes)

Aspose.Zip.ArchiveEntry クラスの新しいインスタンスを初期化します。

protected ArchiveEntry(string name, CompressionSettings compressionSettings, Func<stream> sourceProvider, FileAttributes fileAttributes)

パラメータ

name string

エントリ名。

compressionSettings CompressionSettings

圧縮または解凍の設定。

sourceProvider Func<Stream&gt;

圧縮されるエントリデータを持つストリームを返すメソッド。

fileAttributes FileAttributes

ファイルシステムからの属性。

ArchiveEntry(string, CompressionSettings, Stream, FileAttributes, FileSystemInfo)

Aspose.Zip.ArchiveEntry クラスの新しいインスタンスを初期化します。

protected ArchiveEntry(string name, CompressionSettings compressionSettings, Stream source, FileAttributes fileAttributes, FileSystemInfo fileInfo = null)

パラメータ

name string

エントリ名。

compressionSettings CompressionSettings

圧縮または解凍の設定。

source Stream

圧縮または解凍されるエントリデータを持つストリーム。

fileAttributes FileAttributes

ファイルシステムからの属性。

fileInfo FileSystemInfo

エントリに基づくファイルまたはディレクトリ情報。

プロパティ

Comment

アーカイブ内のエントリのコメントを取得します。

public string Comment { get; protected set; }

プロパティ値

string

CompressedSize

圧縮ファイルのサイズを取得します。

public ulong CompressedSize { get; }

プロパティ値

ulong

CompressionSettings

圧縮または解凍の設定を取得します。

public CompressionSettings CompressionSettings { get; }

プロパティ値

CompressionSettings

DataSource

エントリがアーカイブに追加された場合のソース。

public Stream DataSource { get; }

プロパティ値

Stream

備考

割り当てられる前は、ソースは null です。このソースは、場合によっては Archive.Save メソッド内で割り当てられることがあります。

FileAttributes

ホストシステムからのファイル属性を取得します。

protected FileAttributes FileAttributes { get; }

プロパティ値

FileAttributes

IsDirectory

エントリがディレクトリを表すかどうかを示す値を取得します。

public bool IsDirectory { get; }

プロパティ値

bool

ModificationTime

最終変更日時を取得または設定します。

public DateTime ModificationTime { get; set; }

プロパティ値

DateTime

Name

アーカイブ内のエントリ名を取得します。

public string Name { get; protected set; }

プロパティ値

string

UncompressedSize

元のファイルのサイズを取得します。

public ulong UncompressedSize { get; }

プロパティ値

ulong

メソッド

Extract(string, string)

指定されたパスにファイルシステムにエントリを抽出します。

public FileInfo Extract(string path, string password = null)

パラメータ

path string

宛先ファイルのパス。ファイルが既に存在する場合は、上書きされます。

password string

復号化のためのオプションのパスワード。

戻り値

FileInfo

作成されたファイルのファイル情報。

それぞれ異なるパスワードを持つ2つのエントリをzipアーカイブから抽出します。

using (FileStream zipFile = File.Open("archive.zip", FileMode.Open))
{
    using (Archive archive = new Archive(zipFile))
    {
        archive.Entries[0].Extract("first.bin", "first_pass");
        archive.Entries[1].Extract("second.bin", "second_pass");
    }
}

例外

ArgumentNullException

path が null です。

SecurityException

呼び出し元にはアクセスするための必要な権限がありません。

ArgumentException

path が空であるか、空白のみを含むか、無効な文字を含んでいます。

UnauthorizedAccessException

ファイル path へのアクセスが拒否されました。

PathTooLongException

指定された path、ファイル名、またはその両方がシステム定義の最大長を超えています。たとえば、Windowsベースのプラットフォームでは、パスは248文字未満でなければならず、ファイル名は260文字未満でなければなりません。

NotSupportedException

path に文字列の中間にコロン (:) が含まれています。

FileNotFoundException

ファイルが見つかりません。

DirectoryNotFoundException

指定されたパスが無効である、たとえばマッピングされていないドライブ上にある場合。

IOException

ファイルはすでに開いています。

InvalidDataException

データが破損しています。 -または- エントリの CRC または MAC 検証に失敗しました。

Extract(Stream, string)

指定されたストリームにエントリを抽出します。

public void Extract(Stream destination, string password = null)

パラメータ

destination Stream

宛先ストリーム。書き込み可能でなければなりません。

password string

復号化のためのオプションのパスワード。

パスワードを持つzipアーカイブのエントリを抽出します。

using (FileStream zipFile = File.Open("archive.zip", FileMode.Open))
{
    using (Archive archive = new Archive(zipFile))
    {
        archive.Entries[0].Extract(httpResponseStream, "p@s$");
    }
}

例外

InvalidDataException

データが破損しています。 -または- エントリの CRC または MAC 検証に失敗しました。

IOException

ソースが破損しているか、読み取り不可能です。

ArgumentException

destination は書き込みをサポートしていません。

Open(string)

抽出のためにエントリを開き、解凍されたエントリの内容を持つストリームを提供します。

public Stream Open(string password = null)

パラメータ

password string

復号化のためのオプションのパスワード。

戻り値

Stream

エントリの内容を表すストリーム。

使用法: Stream decompressed = entry.Open();

.NET 4.0 以降 - Stream.CopyTo メソッドを使用: decompressed.CopyTo(httpResponse.OutputStream)

.NET 3.5 およびそれ以前 - バイトを手動でコピー:

byte[] buffer = new byte[8192];
int bytesRead;
while (0 &lt; (bytesRead = decompressed.Read(buffer, 0, buffer.Length)))
 fileStream.Write(buffer, 0, bytesRead);
```</p>

#### 備考

<p>ストリームから読み取ってファイルの元の内容を取得します。例のセクションを参照してください。</p>

#### 例外

[InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception)

アーカイブが不正な状態です。

### <a id="Aspose_Zip_ArchiveEntry_CompressionProgressed"></a> CompressionProgressed

生のストリームの一部が圧縮されたときに発生します。

```csharp
public event EventHandler<progresseventargs> CompressionProgressed

イベントタイプ

EventHandler<ProgressEventArgs&gt;

archive.Entries[0].CompressionProgressed += (s, e) =&gt; { int percent = (int)((100 * (long)e.ProceededBytes) / entrySourceStream.Length); };

備考

イベントの送信者は Aspose.Zip.ArchiveEntry インスタンスです。

ExtractionProgressed

生のストリームの一部が抽出されたときに発生します。

public event EventHandler<progresseventargs> ExtractionProgressed

イベントタイプ

EventHandler<ProgressEventArgs&gt;

archive.Entries[0].ExtractionProgressed += (s, e) =&gt; { int percent = (int)((100 * e.ProceededBytes) / ((ArchiveEntry)s).UncompressedSize); };

備考

イベントの送信者は Aspose.Zip.ArchiveEntry インスタンスです。

 日本語