Class CpioArchive

Class CpioArchive

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

此类表示 cpio 压缩文件。

public class CpioArchive : IArchive, IDisposable

继承

objectCpioArchive

实现

IArchive, IDisposable

继承成员

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

构造函数

CpioArchive()

初始化 Aspose.Zip.Cpio.CpioArchive 类的新实例。

public CpioArchive()

示例

以下示例演示如何压缩文件。

using (var archive = new CpioArchive())
{
    archive.CreateEntry("first.bin", "data.bin");
    archive.Save("archive.cpio");
}

CpioArchive(Stream)

初始化 Aspose.Zip.Cpio.CpioArchive 类的新实例,并组成可以从归档中提取的条目列表。

public CpioArchive(Stream sourceStream)

参数

sourceStream Stream

归档的源。必须是可寻址的。

示例

以下示例演示如何将所有条目提取到目录中。

using (var archive = new CpioArchive(File.OpenRead("archive.cpio")))
{ 
   archive.ExtractToDirectory("C:\extracted");
}

备注

此构造函数不会解压任何条目。有关解压的更多信息,请参见 Aspose.Zip.Cpio.CpioEntry.Open 方法。

异常

ArgumentNullException

sourceStream 为 null。

ArgumentException

sourceStream 不是可寻址的。

InvalidDataException

sourceStream 不是有效的 cpio 压缩文件。

CpioArchive(string)

初始化 Aspose.Zip.Cpio.CpioArchive 类的新实例,并组成可以从归档中提取的条目列表。

public CpioArchive(string path)

参数

path string

归档文件的路径。

示例

以下示例演示如何将所有条目提取到目录中。

using (var archive = new CpioArchive("archive.cpio")) 
{ 
   archive.ExtractToDirectory("C:\extracted");
}

备注

此构造函数不会解压任何条目。有关解压的更多信息,请参见 Aspose.Zip.Cpio.CpioEntry.Open 方法。

异常

ArgumentNullException

path 为 null。

SecurityException

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

ArgumentException

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

UnauthorizedAccessException

对文件 path 的访问被拒绝。

PathTooLongException

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

NotSupportedException

path 中间包含冒号 (:)。

FileNotFoundException

未找到文件。

DirectoryNotFoundException

指定的路径无效,例如位于未映射的驱动器上。

IOException

文件已打开。

属性

Entries

获取构成归档的 Aspose.Zip.Cpio.CpioEntry 类型的条目。

public ReadOnlyCollection<cpioentry> Entries { get; }

属性值

ReadOnlyCollection<CpioEntry&gt;

方法

CreateEntries(string, bool)

将给定目录中的所有文件和目录递归地添加到归档中。

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

参数

sourceDirectory string

要压缩的目录。

includeRootDirectory bool

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

返回

CpioArchive

Cpio 条目实例。

示例

using (FileStream cpioFile = File.Open("archive.cpio", FileMode.Create))
{
    using (var archive = new CpioArchive())
    {
        archive.CreateEntries("C:\folder", false);
        archive.Save(cpioFile);
    }
}

异常

ArgumentNullException

sourceDirectory 为 null。

SecurityException

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

ArgumentException

sourceDirectory 包含无效字符,例如 “、<、> 或 |。

PathTooLongException

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

IOException

sourceDirectory 代表一个文件,而不是一个目录。

CreateEntries(DirectoryInfo, bool)

将给定目录中的所有文件和目录递归地添加到归档中。

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

参数

directory DirectoryInfo

要压缩的目录。

includeRootDirectory bool

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

返回

CpioArchive

Cpio 条目实例。

示例

using (FileStream cpioFile = File.Open("archive.cpio", FileMode.Create))
{
    using (var archive = new CpioArchive())
    {
        archive.CreateEntries(new DirectoryInfo("C:\folder"), false);
        archive.Save(cpioFile);
    }
}

异常

ArgumentNullException

directory 为 null。

SecurityException

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

IOException

directory 代表一个文件,而不是一个目录。

CreateEntry(string, FileInfo, bool)

在归档中创建单个条目。

public CpioEntry CreateEntry(string name, FileInfo fileInfo, bool openImmediately = false)

参数

name string

条目的名称。

fileInfo FileInfo

要压缩的文件或文件夹的元数据。

openImmediately bool

如果立即打开文件,则为 true;否则,在归档保存时打开文件。

返回

CpioEntry

Cpio 条目实例。

示例

FileInfo fileInfo = new FileInfo("data.bin");
using (var archive = new CpioArchive())
{
    archive.CreateEntry("test.bin", fileInfo);
    archive.Save("archive.cpio");
}

备注

如果使用 openImmediately 参数立即打开文件,则在归档被处理之前,该文件将被锁定。

异常

ArgumentNullException

name 为 null。

ArgumentException

name 为空。

ArgumentNullException

fileInfo 为 null。

CreateEntry(string, string, bool)

在归档中创建单个条目。

public CpioEntry CreateEntry(string name, string sourcePath, bool openImmediately = false)

参数

name string

条目的名称。

sourcePath string

要压缩的文件路径。

openImmediately bool

如果立即打开文件,则为 true;否则,在归档保存时打开文件。

返回

CpioEntry

Cpio 条目实例。

示例

using (var archive = new CpioArchive())
{
    archive.CreateEntry("first.bin", "data.bin");
    archive.Save("archive.cpio");
}

备注

条目名称仅在 name 参数中设置。sourcePath 参数中提供的文件名不会影响条目名称。

如果使用 openImmediately 参数立即打开文件,则在归档被处理之前,该文件将被锁定。

异常

ArgumentNullException

sourcePath 为 null。

SecurityException

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

ArgumentException

sourcePath 为空,仅包含空格,或包含无效字符。 - 或 - 文件名,作为 name 的一部分,超过 100 个符号。

UnauthorizedAccessException

对文件 sourcePath 的访问被拒绝。

PathTooLongException

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

NotSupportedException

sourcePath 中间包含冒号 (:)。

CreateEntry(string, Stream)

在归档中创建单个条目。

public CpioEntry CreateEntry(string name, Stream source)

参数

name string

条目的名称。

source Stream

条目的输入流。

返回

CpioEntry

Cpio 条目实例。

示例

using (var archive = new CpioArchive())
{
    archive.CreateEntry("data.bin", File.OpenRead("data.bin"));
    archive.Save("archive.cpio");
}

异常

ArgumentNullException

name 为 null。

ArgumentNullException

source 为 null。

ArgumentException

name 为空。

DeleteEntry(CpioEntry)

从条目列表中删除特定条目的第一个实例。

public CpioArchive DeleteEntry(CpioEntry entry)

参数

entry CpioEntry

要从条目列表中删除的条目。

返回

CpioArchive

Cpio 条目实例。

示例

以下是您可以删除所有条目(除最后一个之外)的方法:

using (var archive = new CpioArchive("archive.cpio"))
{
    while (archive.Entries.Count &gt; 1)
        archive.DeleteEntry(archive.Entries[0]);
    archive.Save(outputCpioFile);
}

异常

ArgumentNullException

entry 为 null。

DeleteEntry(int)

通过索引从条目列表中删除条目。

public CpioArchive DeleteEntry(int entryIndex)

参数

entryIndex int

要删除的条目的零基索引。

返回

CpioArchive

删除条目的归档。

示例

using (var archive = new CpioArchive("two_files.cpio"))
{
    archive.DeleteEntry(0);
    archive.Save("single_file.cpio");
}

异常

ArgumentOutOfRangeException

entryIndex 小于 0。- 或 - entryIndex 等于或大于 Entries 计数。

Dispose()

执行与释放、释放或重置非托管资源相关的应用程序定义的任务。

public void Dispose()

Dispose(bool)

执行与释放、释放或重置非托管资源相关的应用程序定义的任务。

protected virtual void Dispose(bool disposing)

参数

disposing bool

是否应释放托管资源。

ExtractToDirectory(string)

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

public void ExtractToDirectory(string destinationDirectory)

参数

destinationDirectory string

要放置提取文件的目录路径。

示例

using (var archive = new CpioArchive("archive.cpio")) 
{ 
   archive.ExtractToDirectory("C:\extracted");
}

备注

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

异常

ArgumentNullException

path 为 null

PathTooLongException

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

SecurityException

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

NotSupportedException

如果目录不存在,路径包含冒号字符 (:) 但不是驱动器标签的一部分 (“C:")。

ArgumentException

path 是零长度字符串,仅包含空格,或包含一个或多个无效字符。您可以使用 System.IO.Path.GetInvalidPathChars 方法查询无效字符。 - 或 - path 以冒号字符 (:) 为前缀,或仅包含冒号字符。

IOException

指定路径的目录是一个文件。 - 或 - 网络名称未知。

Save(string, CpioFormat)

将归档保存到提供的目标文件。

public void Save(string destinationFileName, CpioFormat cpioFormat = CpioFormat.OldAscii)

参数

destinationFileName string

要创建的归档路径。如果指定的文件名指向现有文件,将会被覆盖。

cpioFormat CpioFormat

定义 cpio 头格式。

示例

using (var archive = new CpioArchive())
{
    archive.CreateEntry("entry1", "data.bin");        
    archive.Save("archive.cpio");
}

备注

可以将归档保存到与加载时相同的路径。 但是,不推荐这样做,因为这种方法使用临时文件进行复制。

异常

ArgumentException

destinationFileName 是零长度字符串,仅包含空格,或包含一个或多个无效字符,如 System.IO.Path.InvalidPathChars 所定义。

ArgumentNullException

destinationFileName 为 null。

PathTooLongException

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

DirectoryNotFoundException

指定的 destinationFileName 无效(例如,它位于未映射的驱动器上)。

IOException

打开文件时发生 I/O 错误。

UnauthorizedAccessException

destinationFileName 指定了只读文件且访问权限不是读取。- 或 - 指定了目录。- 或 - 调用者没有所需权限。

NotSupportedException

destinationFileName 格式无效。

Save(Stream, CpioFormat)

将归档保存到提供的流。

public void Save(Stream output, CpioFormat cpioFormat = CpioFormat.OldAscii)

参数

output Stream

目标流。

cpioFormat CpioFormat

定义 cpio 头格式。

示例

using (FileStream cpioFile = File.Open("archive.cpio", FileMode.Create))
{
    using (var archive = new CpioArchive())
    {
        archive.CreateEntry("entry1", "data.bin");        
        archive.Save(cpioFile);
    }
}

备注

output 必须是可写的。

异常

ArgumentNullException

output 为 null。

ArgumentException

output 不是可写的。 - 或 - output 是我们提取的相同流。 - 或 - 由于格式限制,无法以 cpioFormat 保存归档。

SaveGzipped(Stream, CpioFormat)

将归档保存到带有 gzip 压缩的流。

public void SaveGzipped(Stream output, CpioFormat cpioFormat = CpioFormat.OldAscii)

参数

output Stream

目标流。

cpioFormat CpioFormat

定义 cpio 头格式。

示例

using (FileStream result = File.OpenWrite("result.cpio.gz"))
{
    using (FileStream source = File.Open("data.bin", FileMode.Open, FileAccess.Read))
    {
        using (var archive = new CpioArchive())
        {
            archive.CreateEntry("entry.bin", source);
            archive.SaveGzipped(result);
        }
    }
}

备注

output 必须是可写的。

异常

ArgumentNullException

output 为 null。

ArgumentException

output 不是可写的。

SaveGzipped(string, CpioFormat)

将归档保存到带有 gzip 压缩的路径文件。

public void SaveGzipped(string path, CpioFormat cpioFormat = CpioFormat.OldAscii)

参数

path string

要创建的归档路径。如果指定的文件名指向现有文件,将会被覆盖。

cpioFormat CpioFormat

定义 cpio 头格式。

示例

using (FileStream source = File.Open("data.bin", FileMode.Open, FileAccess.Read))
{
    using (var archive = new CpioArchive())
    {
        archive.CreateEntry("entry.bin", source);
        archive.SaveGzipped("result.cpio.gz");
    }
}

SaveLZMACompressed(Stream, CpioFormat)

将归档保存到带有 LZMA 压缩的流。

public void SaveLZMACompressed(Stream output, CpioFormat cpioFormat = CpioFormat.OldAscii)

参数

output Stream

目标流。

cpioFormat CpioFormat

定义 cpio 头格式。

示例

using (FileStream result = File.OpenWrite("result.cpio.lzma"))
{
    using (FileStream source = File.Open("data.bin", FileMode.Open, FileAccess.Read))
    {
        using (var archive = new CpioArchive())
        {
            archive.CreateEntry("entry.bin", source);
            archive.SaveLZMACompressed(result);
        }
    }
}

备注

output 必须是可写的。

重要提示:cpio 压缩文件在此方法中被组成并压缩,其内容在内部保留。注意内存消耗。

SaveLZMACompressed(string, CpioFormat)

将归档保存到带有 lzma 压缩的路径文件。

public void SaveLZMACompressed(string path, CpioFormat cpioFormat = CpioFormat.OldAscii)

参数

path string

要创建的归档路径。如果指定的文件名指向现有文件,将会被覆盖。

cpioFormat CpioFormat

定义 cpio 头格式。

示例

using (FileStream source = File.Open("data.bin", FileMode.Open, FileAccess.Read))
{
    using (var archive = new CpioArchive())
    {
        archive.CreateEntry("entry.bin", source);
        archive.SaveLZMACompressed("result.cpio.lzma");
    }
}

备注

重要提示:cpio 压缩文件在此方法中被组成并压缩,其内容在内部保留。注意内存消耗。

SaveLzipped(Stream, CpioFormat)

将归档保存到带有 lzip 压缩的流。

public void SaveLzipped(Stream output, CpioFormat cpioFormat = CpioFormat.OldAscii)

参数

output Stream

目标流。

cpioFormat CpioFormat

定义 cpio 头格式。

示例

using (FileStream result = File.OpenWrite("result.cpio.lz"))
{
    using (FileStream source = File.Open("data.bin", FileMode.Open, FileAccess.Read))
    {
        using (var archive = new CpioArchive())
        {
            archive.CreateEntry("entry.bin", source);
            archive.SaveGzipped(result);
        }
    }
}

备注

output 必须是可写的。

异常

ArgumentNullException

output 为 null。

ArgumentException

output 不是可写的。

SaveLzipped(string, CpioFormat)

将归档保存到带有 lzip 压缩的路径文件。

public void SaveLzipped(string path, CpioFormat cpioFormat = CpioFormat.OldAscii)

参数

path string

要创建的归档路径。如果指定的文件名指向现有文件,将会被覆盖。

cpioFormat CpioFormat

定义 cpio 头格式。

示例

using (FileStream source = File.Open("data.bin", FileMode.Open, FileAccess.Read))
{
    using (var archive = new CpioArchive())
    {
        archive.CreateEntry("entry.bin", source);
        archive.SaveGzipped("result.cpio.lz");
    }
}

SaveXzCompressed(Stream, CpioFormat, XzArchiveSettings)

将归档保存到带有 xz 压缩的流。

public void SaveXzCompressed(Stream output, CpioFormat cpioFormat = CpioFormat.OldAscii, XzArchiveSettings settings = null)

参数

output Stream

目标流。

cpioFormat CpioFormat

定义 cpio 头格式。

settings XzArchiveSettings

特定 xz 压缩文件的设置集:字典大小、块大小、检查类型。

示例

using (FileStream result = File.OpenWrite("result.cpio.xz"))
{
    using (FileStream source = File.Open("data.bin", FileMode.Open, FileAccess.Read))
    {
        using (var archive = new CpioArchive())
        {
            archive.CreateEntry("entry.bin", source);
            archive.SaveXzCompressed(result);
        }
    }
}

备注

output 流必须是可写的。

异常

ArgumentNullException

output 为 null。

ArgumentException

output 不是可写的。

SaveXzCompressed(string, CpioFormat, XzArchiveSettings)

将归档保存到带有 xz 压缩的路径文件。

public void SaveXzCompressed(string path, CpioFormat cpioFormat = CpioFormat.OldAscii, XzArchiveSettings settings = null)

参数

path string

要创建的归档路径。如果指定的文件名指向现有文件,将会被覆盖。

cpioFormat CpioFormat

定义 cpio 头格式。

settings XzArchiveSettings

特定 xz 压缩文件的设置集:字典大小、块大小、检查类型。

示例

using (FileStream source = File.Open("data.bin", FileMode.Open, FileAccess.Read))
{
    using (var archive = new CpioArchive())
    {
        archive.CreateEntry("entry.bin", source);
        archive.SaveXzCompressed("result.cpio.xz");
    }
}

SaveZCompressed(Stream, CpioFormat)

将归档保存到带有 Z 压缩的流。

public void SaveZCompressed(Stream output, CpioFormat cpioFormat = CpioFormat.OldAscii)

参数

output Stream

目标流。

cpioFormat CpioFormat

定义 cpio 头格式。

示例

using (FileStream result = File.OpenWrite("result.cpio.Z"))
{
    using (FileStream source = File.Open("data.bin", FileMode.Open, FileAccess.Read))
    {
        using (var archive = new CpioArchive())
        {
            archive.CreateEntry("entry.bin", source);
            archive.SaveZCompressed(result);
        }
    }
}

备注

output 必须是可写的。

异常

ArgumentNullException

output 为 null。

ArgumentException

output 不是可写的。

SaveZCompressed(string, CpioFormat)

将归档保存到带有 Z 压缩的路径文件。

public void SaveZCompressed(string path, CpioFormat cpioFormat = CpioFormat.OldAscii)

参数

path string

要创建的归档路径。如果指定的文件名指向现有文件,将会被覆盖。

cpioFormat CpioFormat

定义 cpio 头格式。

示例

using (FileStream source = File.Open("data.bin", FileMode.Open, FileAccess.Read))
{
    using (var archive = new CpioArchive())
    {
        archive.CreateEntry("entry.bin", source);
        archive.SaveZCompressed("result.cpio.Z");
    }
}

SaveZstandard(Stream, CpioFormat)

将归档保存到带有 Zstandard 压缩的流。

public void SaveZstandard(Stream output, CpioFormat cpioFormat = CpioFormat.OldAscii)

参数

output Stream

目标流。

cpioFormat CpioFormat

定义 cpio 头格式。

示例

using (FileStream result = File.OpenWrite("result.cpio.zst"))
{
    using (FileStream source = File.Open("data.bin", FileMode.Open, FileAccess.Read))
    {
        using (var archive = new CpioArchive())
        {
            archive.CreateEntry("entry.bin", source);
            archive.SaveZstandard(result);
        }
    }
}

备注

output 必须是可写的。

异常

ArgumentNullException

output 为 null。

ArgumentException

output 不是可写的。

SaveZstandard(string, CpioFormat)

将归档保存到带有 Zstandard 压缩的路径文件。

public void SaveZstandard(string path, CpioFormat cpioFormat = CpioFormat.OldAscii)

参数

path string

要创建的归档路径。如果指定的文件名指向现有文件,将会被覆盖。

cpioFormat CpioFormat

定义 cpio 头格式。

示例

using (FileStream source = File.Open("data.bin", FileMode.Open, FileAccess.Read))
{
    using (var archive = new CpioArchive())
    {
        archive.CreateEntry("entry.bin", source);
        archive.SaveZstandard("result.cpio.zst");
    }
}
 中文