Class SevenZipArchiveEntry

Class SevenZipArchiveEntry

命名空间: Aspose.Zip.SevenZip
程序集: Aspose.Zip.dll (25.1.0)

表示7z归档中的单个文件。

public abstract class SevenZipArchiveEntry : IArchiveFileEntry

继承

objectSevenZipArchiveEntry

派生

SevenZipArchiveEntryEncrypted, SevenZipArchiveEntryPlain

实现

IArchiveFileEntry

继承成员

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

备注

将Aspose.Zip.SevenZip.SevenZipArchiveEntry实例转换为Aspose.Zip.SevenZip.SevenZipArchiveEntryEncrypted以确定该条目是否被加密。

构造函数

SevenZipArchiveEntry(SevenZipArchive, string, SevenZipCompressionSettings, Stream, FileAttributes, FileSystemInfo)

初始化Aspose.Zip.SevenZip.SevenZipArchiveEntry类的新实例。

protected SevenZipArchiveEntry(SevenZipArchive parent, string name, SevenZipCompressionSettings compressionSettings, Stream source, FileAttributes fileAttributes, FileSystemInfo fileInfo = null)

参数

parent SevenZipArchive

name string

条目名称。

compressionSettings SevenZipCompressionSettings

压缩或解压缩的设置。

source Stream

包含要压缩或解压缩的条目数据的流。

fileAttributes FileAttributes

来自文件系统的属性。

fileInfo FileSystemInfo

条目基于的文件或目录信息。

异常

ArgumentException

name 为 null 或空。

属性

CompressedSize

获取压缩文件的大小。

public ulong CompressedSize { get; }

属性值

ulong

CompressionSettings

获取压缩或解压缩的设置。

public SevenZipCompressionSettings CompressionSettings { get; }

属性值

SevenZipCompressionSettings

FileAttributes

获取主机系统中的文件属性。

protected FileAttributes FileAttributes { get; }

属性值

FileAttributes

IsDirectory

获取一个值,指示条目是否表示目录。

public bool IsDirectory { get; }

属性值

bool

ModificationTime

获取最后修改的日期和时间。

public DateTime ModificationTime { get; }

属性值

DateTime

Name

获取归档中条目的名称。

public string Name { get; protected set; }

属性值

string

Source

获取条目的数据源流。

protected Stream Source { get; set; }

属性值

Stream

UncompressedSize

获取原始文件的大小。

public ulong UncompressedSize { get; }

属性值

ulong

方法

Extract(string, string)

通过提供的路径将条目提取到文件系统。

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

参数

path string

目标文件的路径。如果文件已存在,将被覆盖。

password string

可选的解密密码。

返回

FileInfo

组合文件的信息。

示例

using (var archive = new SevenZipArchive("archive.7z"))
{
    archive.Entries[0].Extract("data.bin");
}

异常

ArgumentNullException

path 为 null。

SecurityException

调用者没有访问所需的权限。

ArgumentException

path 为空,或仅包含空格,或包含无效字符。

UnauthorizedAccessException

对文件path的访问被拒绝。

PathTooLongException

指定的path、文件名或两者超过系统定义的最大长度。例如,在基于Windows的平台上,路径必须少于248个字符,文件名必须少于260个字符。

NotSupportedException

path中的文件包含中间的冒号(:)。

InvalidDataException

归档文件已损坏。

Extract(Stream, string)

将条目提取到提供的流中。

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

参数

destination Stream

目标流。必须可写。

password string

可选的解密密码。

示例

提取带有密码的zip归档条目。

using (var archive = new SevenZipArchive("archive.7z"))
{
    archive.Entries[0].Extract(httpResponseStream);
}

异常

ArgumentException

destination不支持写入。

InvalidOperationException

归档未打开以进行提取。 - 或 - 此条目是一个目录。

InvalidDataException

条目中的数据错误。

FinalizeCompressedData(Stream, byte[])

将任何跟随压缩数据的头写入输出流。

protected abstract int FinalizeCompressedData(Stream outputStream, byte[] encoderProperties)

参数

outputStream Stream

条目的输出流。

encoderProperties byte[]

压缩器的属性。

返回

int

在条目显著数据块之后添加的“技术”字节数。

GetDestinationStream(Stream)

条目的目标流,可能会被修饰。

protected abstract Stream GetDestinationStream(Stream outputStream)

参数

outputStream Stream

条目的输出流。

返回

Stream

条目压缩的目标流。

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 < (bytesRead = decompressed.Read(buffer, 0, buffer.Length)))
 fileStream.Write(buffer, 0, bytesRead);
```</p>

#### 备注

从流中读取以获取文件的原始内容。请参见示例部分。

#### 异常

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

归档未打开以进行提取。 -  - 此条目是一个目录。

 [InvalidDataException](https://learn.microsoft.com/dotnet/api/system.io.invaliddataexception)

条目中的数据错误。

### <a id="Aspose_Zip_SevenZip_SevenZipArchiveEntry_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.SevenZip.SevenZipArchiveEntry实例。

在多线程模式下不对LZMA2条目调用。

 中文