Class ArchiveEntry

Class ArchiveEntry

名称: Aspose.Zip 收藏: Aspose.Zip.dll (25.5.0)

代表单个文件在档案中。

public abstract class ArchiveEntry : IArchiveFileEntry

Inheritance

object ArchiveEntry

Derived

ArchiveEntryEncrypted , ArchiveEntryPlain

Implements

IArchiveFileEntry

继承人

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

Remarks

将 Aspose.Zip.ArchiveEntry 示例插入到 Aspose.Zip.ArchiveEntry 加密,以确定输入是否加密。

Constructors

ArchiveEntry(字符串, CompressionSettings, Func饰 UIN)

启动 Aspose.Zip.ArchiveEntry 类的新例子。

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

Parameters

name string

入口名称

compressionSettings CompressionSettings

设置压缩或压缩。

sourceProvider Func < Stream >

返回流的方法与输入数据也要压缩。

fileAttributes uint

来自文件系统的属性。

ArchiveEntry(字符串, CompressionSettings, Stream, uint, FileSystemInfo)

启动 Aspose.Zip.ArchiveEntry 类的新例子。

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

Parameters

name string

入口名称

compressionSettings CompressionSettings

设置压缩或压缩。

source Stream

输入数据的流量要压缩或压缩。

fileAttributes uint

来自文件系统的属性。

fileInfo FileSystemInfo

文件或目录信息基于输入。

Properties

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

Remarks

在分配之前,源是零. 在某些情况下,这个源可以在“档案保存”方法中分配。

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

Methods

Extract(字符串, string)

通过提供的路径将输入到文件系统。

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

Parameters

path string

路径到目的地文件. 如果文件已经存在,它将被过写。

password string

可选的密码来解密。

Returns

FileInfo

组成文件的文件信息。

Examples

提取 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");
    }
}

Exceptions

ArgumentNullException

path’ is null.

SecurityException

召唤者没有所需的访问许可。

ArgumentException

path’ 是空的,只包含白色空间,或包含无效的字符。

UnauthorizedAccessException

拒绝访问 path" 文件。

PathTooLongException

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

NotSupportedException

文件在 path’ 中间包含一个列(:)。

FileNotFoundException

文件未找到。

DirectoryNotFoundException

指定的路径是无效的,例如在无地图驱动器上。

IOException

文件已经开放了。

InvalidDataException

数据被破坏 - 或 - CRC 或 MAC 验证失败了输入。

Extract(流, string)

将输入到提供的流。

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

Parameters

destination Stream

目的地流,必须写作。

password string

可选的密码来解密。

Examples

用密码提取 zip 档案的输入。

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

Exceptions

InvalidDataException

数据被破坏 - 或 - CRC 或 MAC 验证失败了输入。

IOException

源是腐败的,还是不可读的。

ArgumentException

destination’ does not support writing.

Open(线条)

打开输入用于提取,并提供压缩输入内容的流量。

public Stream Open(string password = null)

Parameters

password string

可选的密码来解密。

Returns

Stream

代表入口内容的流。

Examples

使用: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>

#### Remarks

<p>Read from the stream to get the original content of a file. See examples section.</p>

#### Exceptions

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

The archive is in an incorrect state.

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

Raises when a portion of raw stream compressed.

```csharp
public event EventHandler<progresseventargs> CompressionProgressed

事件类型

EventHandler < ProgressEventArgs >

Examples

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

Remarks

事件发送器是一个 Aspose.Zip.ArchiveEntry 例子。

ExtractionProgressed

当一部分原料流被提取时,它会增加。

public event EventHandler<progresseventargs> ExtractionProgressed

事件类型

EventHandler < ProgressEventArgs >

Examples

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

Remarks

事件发送器是一个 Aspose.Zip.ArchiveEntry 例子。

 中文