Archive.Archive
内容
[
隐藏
]Archive(ArchiveEntrySettings)
初始化一个新的实例Archive
类及其条目的可选设置.
public Archive(ArchiveEntrySettings newEntrySettings = null)
范围 | 类型 | 描述 |
---|---|---|
newEntrySettings | ArchiveEntrySettings | 用于新添加的压缩和加密设置ArchiveEntry items. 如果未指定,将使用最常见的没有加密的 Deflate 压缩。 |
例子
以下示例显示如何使用默认设置压缩单个文件。
using (FileStream zipFile = File.Open("archive.zip", FileMode.Create))
{
using (var archive = new Archive())
{
archive.CreateEntry("data.bin", "file.dat");
archive.Save(zipFile);
}
}
也可以看看
- class ArchiveEntrySettings
- class Archive
- 命名空间 Aspose.Zip
- 部件 Aspose.Zip
Archive(Stream, ArchiveLoadOptions, ArchiveEntrySettings)
初始化一个新的实例Archive
可以从存档中提取类和组合条目列表。
public Archive(Stream sourceStream, ArchiveLoadOptions loadOptions = null,
ArchiveEntrySettings newEntrySettings = null)
范围 | 类型 | 描述 |
---|---|---|
sourceStream | Stream | 存档的来源。 |
loadOptions | ArchiveLoadOptions | 加载现有存档的选项。 |
newEntrySettings | ArchiveEntrySettings | 用于新添加的压缩和加密设置ArchiveEntry items. 如果未指定,将使用最常见的没有加密的 Deflate 压缩。 |
例外
例外 | (健康)状况 |
---|---|
ArgumentException | sourceStream不可搜索。 |
InvalidDataException | AES 的加密标头与 WinZip 压缩方法相矛盾。 |
评论
此构造函数不解压缩任何条目。看Open
解压方法.
例子
以下示例提取加密存档,然后将第一个条目解压缩为内存流
.
var fs = File.OpenRead("encrypted.zip");
var extracted = new MemoryStream();
using (Archive archive = new Archive(fs, new ArchiveLoadOptions() { DecryptionPassword = "p@s$" }))
{
using (var decompressed = archive.Entries[0].Open())
{
byte[] b = new byte[8192];
int bytesRead;
while (0 < (bytesRead = decompressed.Read(b, 0, b.Length)))
extracted.Write(b, 0, bytesRead);
}
}
也可以看看
- class ArchiveLoadOptions
- class ArchiveEntrySettings
- class Archive
- 命名空间 Aspose.Zip
- 部件 Aspose.Zip
Archive(string, ArchiveLoadOptions, ArchiveEntrySettings)
初始化一个新的实例Archive
可以从存档中提取类和组合条目列表。
public Archive(string path, ArchiveLoadOptions loadOptions = null,
ArchiveEntrySettings newEntrySettings = null)
范围 | 类型 | 描述 |
---|---|---|
path | String | 存档文件的完全限定路径或相对路径。 |
loadOptions | ArchiveLoadOptions | 加载现有存档的选项。 |
newEntrySettings | ArchiveEntrySettings | 用于新添加的压缩和加密设置ArchiveEntry items. 如果未指定,将使用最常见的没有加密的 Deflate 压缩。 |
例外
例外 | (健康)状况 |
---|---|
ArgumentNullException | path一片空白。 |
SecurityException | 调用者没有所需的访问权限。 |
ArgumentException | 这path为空、仅包含空格或包含无效字符。 |
UnauthorizedAccessException | 访问文件path被拒绝。 |
PathTooLongException | 指定的path、文件名或两者都超过了系统定义的最大长度。例如,在基于 Windows 的平台上,路径必须少于 248 个字符,文件名必须少于 260 个字符。 |
NotSupportedException | 归档于path在字符串中间包含一个冒号 (:)。 |
评论
此构造函数不解压缩任何条目。看Open
解压方法.
例子
以下示例提取加密存档,然后将第一个条目解压缩为内存流
.
var extracted = new MemoryStream();
using (Archive archive = new Archive("encrypted.zip", new ArchiveLoadOptions() { DecryptionPassword = "p@s$" }))
{
using (var decompressed = archive.Entries[0].Open())
{
byte[] b = new byte[8192];
int bytesRead;
while (0 < (bytesRead = decompressed.Read(b, 0, b.Length)))
extracted.Write(b, 0, bytesRead);
}
}
也可以看看
- class ArchiveLoadOptions
- class ArchiveEntrySettings
- class Archive
- 命名空间 Aspose.Zip
- 部件 Aspose.Zip