Class SevenZipArchive

Class SevenZipArchive

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

此类代表 7z 档案文件. 使用它编写和提取 7z 档案。

public class SevenZipArchive : IArchive, IDisposable

Inheritance

object SevenZipArchive

Implements

IArchive , IDisposable

继承人

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

Constructors

SevenZipArchive(SevenZipEntrySettings)

启动 Aspose.Zip.SevenZip.SevenZipArchive 类的新例子,其输入可选设置。

public SevenZipArchive(SevenZipEntrySettings newEntrySettings = null)

Parameters

newEntrySettings SevenZipEntrySettings

压缩和加密设置用于新增的 Aspose.Zip.SevenZip.SevenZipArchiveEntry 项目。如果没有说明,LZMA压缩没有加密将被使用。

Examples

下面的例子表明如何用默认设置压缩单个文件:LZMA压縮没有加密。

using (FileStream sevenZipFile = File.Open("archive.7z", FileMode.Create))
{
    using (var archive = new SevenZipArchive())
    {
        archive.CreateEntry("data.bin", "file.dat");
        archive.Save(sevenZipFile);
    }
}

SevenZipArchive(流, string)

启动 Aspose.Zip.SevenZip.SevenZipArchive 类的新例子,并组成可以从档案中提取的输入列表。

public SevenZipArchive(Stream sourceStream, string password = null)

Parameters

sourceStream Stream

档案的来源。

password string

可选密码解密:如果文件名被加密,则必须存在。

Examples

using (SevenZipArchive archive = new SevenZipArchive(File.OpenRead("archive.7z")))
{
    archive.ExtractToDirectory("C:\\extracted");
}

Remarks

此构建器不会压缩任何输入. 查看 Aspose.Zip.SevenZip.SevenZipArchive.ExtractToDirectory(System.String,System.String)压缩方法。

Exceptions

ArgumentException

sourceStream’ is not seekable.

ArgumentNullException

sourceStream’ is null.

NotImplementedException

存档包含多个编码器. 现在只有 LZMA 压缩支持。

SevenZipArchive(字符串, string)

启动 Aspose.Zip.SevenZip.SevenZipArchive 类的新例子,并组成可以从档案中提取的输入列表。

public SevenZipArchive(string path, string password = null)

Parameters

path string

完全合格的或相对的路径到档案文件。

password string

可选密码解密:如果文件名被加密,则必须存在。

Examples

using (SevenZipArchive archive = new SevenZipArchive("archive.7z"))
{
    archive.ExtractToDirectory("C:\\extracted");
}

Remarks

此构建器不会压缩任何输入. 查看 Aspose.Zip.SevenZip.SevenZipArchive.ExtractToDirectory(System.String,System.String)压缩方法。

Exceptions

ArgumentNullException

path’ is null.

SecurityException

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

ArgumentException

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

UnauthorizedAccessException

拒绝访问 path" 文件。

PathTooLongException

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

NotSupportedException

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

FileNotFoundException

文件未找到。

DirectoryNotFoundException

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

IOException

文件已经开放了。

SevenZipArchive(线条( ), String)

启动一个新的例子 Aspose.Zip.SevenZip.SevenZipArchive 类从多卷 7z 档案库,并组成一个可以从档案库中提取的输入列表。

public SevenZipArchive(string[] parts, string password = null)

Parameters

parts string ( )

路径到各个多容量7z档案的序列

password string

可选密码解密:如果文件名被加密,则必须存在。

Examples

using (SevenZipArchive archive = new SevenZipArchive(new string[] { "multi.7z.001", "multi.7z.002", "multi.7z.003" }))
{
    archive.ExtractToDirectory("C:\\extracted");
}

Exceptions

ArgumentNullException

parts’ is null.

ArgumentException

parts’ has no entries.

SecurityException

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

ArgumentException

到文件的路径是空的,仅包含白色空间,或包含无效的字符。

UnauthorizedAccessException

对文件的访问被拒绝。

PathTooLongException

例如,在基于 Windows 的平台上,路径必须小于 248 个字符,文件名必须小于 260 个字符。

NotSupportedException

一条路上的文件包含一条列(:)在线的中间。

Properties

Entries

收到 Aspose.Zip.SevenZip.SevenZipArchiveEntry 类型的输入,构成档案。

public ReadOnlyCollection<sevenziparchiveentry> Entries { get; }

财产价值

ReadOnlyCollection < SevenZipArchiveEntry >

NewEntrySettings

压缩和加密设置用于新增的 Aspose.Zip.SevenZip.SevenZipArchiveEntry 项目。

public SevenZipEntrySettings NewEntrySettings { get; }

财产价值

SevenZipEntrySettings

Methods

CreateEntries(首页 > 博尔)

将所有文件和目录重复添加到所提供的目录中。

public SevenZipArchive CreateEntries(DirectoryInfo directory, bool includeRootDirectory = true)

Parameters

directory DirectoryInfo

编辑器压缩。

includeRootDirectory bool

指示是否要包含根目录本身。

Returns

SevenZipArchive

编写的存档与输入。

Examples

using (SevenZipArchive archive = new SevenZipArchive())
{
    DirectoryInfo folder = new DirectoryInfo("C:\folder");
    archive.CreateEntries(folder);
    archive.Save("folder.7z");
}

Exceptions

DirectoryNotFoundException

通往 directory’ 的路径是无效的,例如在无地图驱动器上。

SecurityException

通话者没有必要的许可访问 directory。

CreateEntries(布尔,布尔)

将所有文件和目录重复添加到所提供的目录中。

public SevenZipArchive CreateEntries(string sourceDirectory, bool includeRootDirectory = true)

Parameters

sourceDirectory string

编辑器压缩。

includeRootDirectory bool

指示是否要包含根目录本身。

Returns

SevenZipArchive

编写的存档与输入。

Examples

将 7z 存档与 LZMA2 压缩组成。

using (SevenZipArchive archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMACompressionSettings())))
{
    archive.CreateEntries("C:\folder");
    archive.Save("folder.7z");
}

CreateEntry(字符串, FileInfo, bool, SevenZipEntrySettings)

在档案中创建一个单一输入。

public SevenZipArchiveEntry CreateEntry(string name, FileInfo fileInfo, bool openImmediately = false, SevenZipEntrySettings newEntrySettings = null)

Parameters

name string

入口的名称。

fileInfo FileInfo

要压缩的文件的代码。

openImmediately bool

事实上,如果立即打开文件,否则在存储档案上打开文件。

newEntrySettings SevenZipEntrySettings

压缩和加密设置用于添加 Aspose.Zip.SevenZip.SevenZipArchiveEntry 项目。

Returns

SevenZipArchiveEntry

7 Zip 入口例子

Examples

组成存档与各个不同的密码加密的输入。

using (FileStream sevenZipFile = File.Open("archive.7z", FileMode.Create))
{
    FileInfo fi1 = new FileInfo("data1.bin");
    FileInfo fi2 = new FileInfo("data2.bin");
    FileInfo fi3 = new FileInfo("data3.bin");
    using (var archive = new SevenZipArchive())
    {
        archive.CreateEntry("entry1.bin", fi1, false, new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(), new SevenZipAESEncryptionSettings("test1")));
        archive.CreateEntry("entry2.bin", fi2, false, new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(), new SevenZipAESEncryptionSettings("test2")));
        archive.CreateEntry("entry3.bin", fi3, false, new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(), new SevenZipAESEncryptionSettings("test3")));
        archive.Save(sevenZipFile);
    }
}

Remarks

输入名单仅在参数中设置,参数中提供的文件名不影响输入名单。

如果文件与参数立即打开,它将被阻止,直到存储文件。

Exceptions

UnauthorizedAccessException

fileInfo’ is read-only or is a directory.

DirectoryNotFoundException

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

IOException

文件已经开放了。

CreateEntry(字符串, 流, SevenZipEntrySettings, FileSystemInfo)

在档案中创建一个单一输入。

public SevenZipArchiveEntry CreateEntry(string name, Stream source, SevenZipEntrySettings newEntrySettings, FileSystemInfo fileInfo)

Parameters

name string

入口的名称。

source Stream

输入流的输入流。

newEntrySettings SevenZipEntrySettings

压缩和加密设置用于添加 Aspose.Zip.SevenZip.SevenZipArchiveEntry 项目。

fileInfo FileSystemInfo

要压缩的文件或文件夹的代码。

Returns

SevenZipArchiveEntry

7Zip入口。

Examples

用 LZMA2 压缩加密输入组成档案。

using (FileStream sevenZipFile = File.Open("archive.7z", FileMode.Create))
{
    using (var archive = new SevenZipArchive())
    {
        archive.CreateEntry("entry1.bin", new MemoryStream(new byte[] {0x00, 0xFF}), new SevenZipEntrySettings(new SevenZipLZMA2CompressionSettings(), new SevenZipAESEncryptionSettings("test1")), new FileInfo("data1.bin")); 
        archive.Save(sevenZipFile);
    }
}

Remarks

输入名单仅在参数中设置,参数中提供的文件名不影响输入名单。

可以提到 System.IO.DirectoryInfo 如果输入是目录。

Exceptions

InvalidOperationException

source’ and fileInfo’ are null or source’ is null and fileInfo’ stands for directory。

CreateEntry(字符串, 流, SevenZipEntrySettings)

在档案中创建一个单一输入。

public SevenZipArchiveEntry CreateEntry(string name, Stream source, SevenZipEntrySettings newEntrySettings = null)

Parameters

name string

入口的名称。

source Stream

输入流的输入流。

newEntrySettings SevenZipEntrySettings

压缩和加密设置用于添加 Aspose.Zip.SevenZip.SevenZipArchiveEntry 项目。

Returns

SevenZipArchiveEntry

Zip 入口。

Examples

将 7z 存档与 LZMA2 压缩和加密所有输入。

using (var archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMA2CompressionSettings(), new SevenZipAESEncryptionSettings("p@s$"))))
{
    archive.CreateEntry("data.bin", new MemoryStream(new byte[] {0x00, 0xFF} ));
    archive.Save("archive.7z");
}

CreateEntry(字符串,字符串, Bool, SevenZipEntrySettings)

在档案中创建一个单一输入。

public SevenZipArchiveEntry CreateEntry(string name, string path, bool openImmediately = false, SevenZipEntrySettings newEntrySettings = null)

Parameters

name string

入口的名称。

path string

新文件的完全合格名称,或者要压缩的相对文件名。

openImmediately bool

事实上,如果立即打开文件,否则在存储档案上打开文件。

newEntrySettings SevenZipEntrySettings

压缩和加密设置用于添加 Aspose.Zip.SevenZip.SevenZipArchiveEntry 项目。

Returns

SevenZipArchiveEntry

Zip 入口。

Examples

using (FileStream sevenZipFile = File.Open("archive.7z", FileMode.Create))
{
    using (var archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMA2CompressionSettings())))
    {
        archive.CreateEntry("data.bin", "file.dat");
        archive.Save(sevenZipFile);
    }
}

Remarks

输入名单仅在参数中设置,参数中提供的文件名不影响输入名单。

如果文件与参数立即打开,它将被阻止,直到存储文件。

Exceptions

ArgumentNullException

path’ is null.

SecurityException

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

ArgumentException

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

UnauthorizedAccessException

拒绝访问 path" 文件。

PathTooLongException

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

NotSupportedException

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

Dispose()

执行与释放、释放或重新管理未管理资源相关的应用定义任务。

public void Dispose()

Dispose(博尔)

执行与释放、释放或重新管理未管理资源相关的应用定义任务。

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

管理的资源是否要消耗?

ExtractToDirectory(字符串, string)

将存档中的所有文件提取到所提供的目录中。

public void ExtractToDirectory(string destinationDirectory, string password = null)

Parameters

destinationDirectory string

路径到目录将提取的文件插入。

password string

可选的密码为内容解密。

Examples

using (var archive = new SevenZipArchive("archive.7z")) 
{ 
   archive.ExtractToDirectory("C:\extracted");
}

Remarks

如果目录不存在,它将被创建。

如果文件名被加密,请输入 Aspose. Zip.SevenZipArchive.#ctor(System.String,Sistem. String) 或 __ WL51.Zips. SevenZibarchive。

Exceptions

ArgumentNullException

destinationDirectory’ is null.

PathTooLongException

例如,在基于 Windows 的平台上,路径必须小于 248 个字符,文件名必须小于 260 个字符。

SecurityException

呼叫者没有必要的许可访问现有目录。

NotSupportedException

如果目录不存在,路径包含一个列符(:)不属于驱动标签(“C:”)的一部分。

ArgumentException

destinationDirectory’ is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the System.IO.Path.GetInvalidPathChars method. -or- path is prefixed with, or contains, only a colon character (:).

IOException

路径指定的目录是一个文件. -or- 网络名称不明。

InvalidDataException

档案被腐败了。

Save(Stream)

保存 7z 存档到提供的流量。

public void Save(Stream output)

Parameters

output Stream

目的地流

Examples

using (FileStream sevenZipFile = File.Open("archive.7z", FileMode.Create))
{
  using (FileStream source = File.Open("data.bin", FileMode.Open, FileAccess.Read))
  {
    using (var archive = new SevenZipArchive())
    {
      archive.CreateEntry("data", source);
      archive.Save(sevenZipFile);
    }
  }
}

Remarks

必须是可寻求的。

Exceptions

ArgumentException

output’ does not support seeking.

ArgumentNullException

output’ is null.

InvalidOperationException

编码器无法压缩数据。

Save(线条)

存储存档到提供的目的地文件。

public void Save(string destinationFileName)

Parameters

destinationFileName string

要创建档案的路径 如果指定的文件名指向现有文件,则将重写。

Examples

using (FileStream source = File.Open("data.bin", FileMode.Open, FileAccess.Read))
{
   using (var archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMACompressionSettings())))
   {
      archive.CreateEntry("data", source);
      archive.Save("archive.7z");
   }
}

Remarks

可以将档案存储到它从下载的同一条路径,但是,这并不建议,因为这种方法使用复制到临时文件。

Exceptions

ArgumentNullException

destinationFileName’ is null.

SecurityException

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

ArgumentException

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

UnauthorizedAccessException

拒绝访问 destinationFileName’ 文件。

PathTooLongException

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

NotSupportedException

文件在 destinationFileName’ 包含字符串中间的一个列(:)。

SaveSplit(字符串, SplitSevenZipArchiveSaveOptions)

存储多容量档案到提供的目的地目录。

public void SaveSplit(string destinationDirectory, SplitSevenZipArchiveSaveOptions options)

Parameters

destinationDirectory string

路径到要创建档案部分的目录。

options SplitSevenZipArchiveSaveOptions

存储档案的选项,包括文件名。

Examples

using (SevenZipArchive archive = new SevenZipArchive())
{
    archive.CreateEntry("entry.bin", "data.bin");
    archive.SaveSplit(@"C:\Folder",  new SplitSevenZipArchiveSaveOptions("volume", 65536));
}

Remarks

此方法由多个( )文件组成 filename.7z.001, filename.7z.002, …, filename.7z(n)。

无法创建现有档案多容量。

Exceptions

InvalidOperationException

此档案从现有来源打开。

ArgumentNullException

destinationDirectory’ is null.

SecurityException

召唤者没有必要的许可访问目录。

ArgumentException

destinationDirectory’ contains invalid characters such as “, >, <, or |.

PathTooLongException

指定的路径超过系统定义的最大长度。

 中文