Class CpioArchive

Class CpioArchive

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

此类代表 cpio 档案文件。

public class CpioArchive : IArchive, IDisposable

Inheritance

object CpioArchive

Implements

IArchive , IDisposable

继承人

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

Constructors

CpioArchive()

启动了 Aspose.Zip.Cpio.Cpio 档案类的新例子。

public CpioArchive()

Examples

下面的例子表明如何压缩文件。

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)

Parameters

sourceStream Stream

資料來源:必須可搜尋。

Examples

下面的示例显示如何将所有输入提取到一个目录。

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

Remarks

此制造商不会解包任何输入. 查看 Aspose.Zip.Cpio.CpioEntry.Open 解包方法。

Exceptions

ArgumentNullException

sourceStream’ is null.

ArgumentException

sourceStream’ is not seekable.

InvalidDataException

sourceStream’ is not valid cpio archive.

CpioArchive(线条)

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

public CpioArchive(string path)

Parameters

path string

走向档案的路径。

Examples

下面的示例显示如何将所有输入提取到一个目录。

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

Remarks

此制造商不会解包任何输入. 查看 Aspose.Zip.Cpio.CpioEntry.Open 解包方法。

Exceptions

ArgumentNullException

path’ is null.

SecurityException

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

ArgumentException

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

UnauthorizedAccessException

拒绝访问 path" 文件。

PathTooLongException

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

NotSupportedException

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

FileNotFoundException

文件未找到。

DirectoryNotFoundException

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

IOException

文件已经开放了。

Properties

Entries

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

public ReadOnlyCollection<cpioentry> Entries { get; }

财产价值

ReadOnlyCollection < CpioEntry >

Methods

CreateEntries(布尔,布尔)

将所有文件和目录重复添加到存档中。

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

Parameters

sourceDirectory string

编辑器压缩。

includeRootDirectory bool

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

Returns

CpioArchive

Cpio 入口案例

Examples

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

Exceptions

ArgumentNullException

sourceDirectory’ is null.

SecurityException

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

ArgumentException

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

PathTooLongException

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

IOException

sourceDirectory’ stands for a file, not for a directory.

CreateEntries(首页 > 博尔)

将所有文件和目录重复添加到存档中。

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

Parameters

directory DirectoryInfo

编辑器压缩。

includeRootDirectory bool

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

Returns

CpioArchive

Cpio 入口案例

Examples

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

Exceptions

ArgumentNullException

directory’ is null.

SecurityException

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

IOException

directory’ stands for a file, not for a directory.

CreateEntry(字符串,FileInfo,bool)

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

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

Parameters

name string

入口的名称。

fileInfo FileInfo

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

openImmediately bool

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

Returns

CpioEntry

Cpio 入口案例

Examples

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

Remarks

如果文件与参数立即打开,它将被阻止,直到档案被删除。

Exceptions

ArgumentNullException

name’ is null.

ArgumentException

name’ is empty.

ArgumentNullException

fileInfo’ is null.

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

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

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

Parameters

name string

入口的名称。

sourcePath string

文件要压缩的路径。

openImmediately bool

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

Returns

CpioEntry

Cpio 入口案例

Examples

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

Remarks

输入名单仅在参数中设置,参数中提供的文件名不影响输入名单。 如果文件与参数立即打开,它将被阻止,直到档案被删除。

Exceptions

ArgumentNullException

sourcePath’ is null.

SecurityException

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

ArgumentException

sourcePath’ 是空的,只包含白色空间,或包含无效的字符. - 或 - 文件名,作为 name’ 的部分,超过 100 个符号。

UnauthorizedAccessException

拒绝访问 sourcePath’ 文件。

PathTooLongException

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

NotSupportedException

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

CreateEntry(流,流)

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

public CpioEntry CreateEntry(string name, Stream source)

Parameters

name string

入口的名称。

source Stream

输入流的输入流。

Returns

CpioEntry

Cpio 入口案例

Examples

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

Exceptions

ArgumentNullException

name’ is null.

ArgumentNullException

source’ is null.

ArgumentException

name’ is empty.

DeleteEntry(CpioEntry)

从输入列表中删除特定输入的第一次出现。

public CpioArchive DeleteEntry(CpioEntry entry)

Parameters

entry CpioEntry

输入要从输入列表中删除。

Returns

CpioArchive

Cpio 入口案例

Examples

下面是如何删除所有输入,除了最后一个:

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

Exceptions

ArgumentNullException

entry’ is null.

DeleteEntry(因特)

按指数从输入列表中删除输入。

public CpioArchive DeleteEntry(int entryIndex)

Parameters

entryIndex int

以零为基础的输入指数要删除。

Returns

CpioArchive

包含输入的档案已删除。

Examples

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

Exceptions

ArgumentOutOfRangeException

entryIndex’ is less than 0.-or- entryIndex’ is equal to or greater than ‘Entries’ count.

Dispose()

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

public void Dispose()

Dispose(博尔)

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

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

管理的资源是否要消耗?

ExtractToDirectory(线条)

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

public void ExtractToDirectory(string destinationDirectory)

Parameters

destinationDirectory string

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

Examples

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

Remarks

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

Exceptions

ArgumentNullException

路是零

PathTooLongException

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

SecurityException

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

NotSupportedException

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

ArgumentException

路径是零长的线条,仅包含白空间,或包含一个或多个无效的字符. 您可以使用 System.IO.Path.GetInvalidPathChars 方法查询无效的字符。

IOException

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

Save(字符串,CpioFormat)

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

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

Parameters

destinationFileName string

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

cpioFormat CpioFormat

定义 cpio header 格式

Examples

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

Remarks

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

Exceptions

ArgumentException

destinationFileName’ is a zero-length string, contains only white space, or contains one or more invalid characters as defined by System.IO.Path.InvalidPathChars.

ArgumentNullException

destinationFileName’ is null.

PathTooLongException

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

DirectoryNotFoundException

指定的 destinationFileName’ 是无效的,(例如,它在一个未地图的驱动器上)。

IOException

在打开文件时出现了 I/O 错误。

UnauthorizedAccessException

destinationFileName’Specified a file is read-only and access is not Read.-or- path specified a directory.-or- The caller does not have the required permission.

NotSupportedException

destinationFileName’ is in an invalid format.

Save(流量,CpioFormat)

存储存档到提供的流量。

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

Parameters

output Stream

目的地流

cpioFormat CpioFormat

定义 cpio header 格式

Examples

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

Remarks

必须是可写的。

Exceptions

ArgumentNullException

output’ is null.

ArgumentException

output’ is not writable. - or - output’ is the same stream we extract from.- OR -It is impossible to save archive in cpioFormat’ due to format restrictions.

SaveGzipped(流量,CpioFormat)

通过 gzip 压缩,存储存档到流。

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

Parameters

output Stream

目的地流

cpioFormat CpioFormat

定义 cpio header 格式

Examples

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);
        }
    }
}

Remarks

必须是可写的。

Exceptions

ArgumentNullException

output’ is null.

ArgumentException

output’ is not writable.

SaveGzipped(字符串,CpioFormat)

通过 gzip 压缩将文件存储到文件中。

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

Parameters

path string

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

cpioFormat CpioFormat

定义 cpio header 格式

Examples

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

安慰 压缩(流量,CpioFormat)

通过 LZMA 压缩将档案存储到流中。

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

Parameters

output Stream

目的地流

cpioFormat CpioFormat

定义 cpio header 格式

Examples

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);
        }
    }
}

Remarks

必须是可写的。 重要: cpio 档案组成,然后在此方法中压缩,其内容被内部保存。

安慰 压缩(字符串,CpioFormat)

通过 lzma 压缩路径将文件存储到文件中。

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

Parameters

path string

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

cpioFormat CpioFormat

定义 cpio header 格式

Examples

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

Remarks

重要: cpio 档案组成,然后在此方法中压缩,其内容被内部保存。

SaveLzipped(流量,CpioFormat)

通过 lzip 压缩,存储存档到流。

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

Parameters

output Stream

目的地流

cpioFormat CpioFormat

定义 cpio header 格式

Examples

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);
        }
    }
}

Remarks

必须是可写的。

Exceptions

ArgumentNullException

output’ is null.

ArgumentException

output’ is not writable.

SaveLzipped(字符串,CpioFormat)

通过 lzip 压缩将文件存储到文件中。

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

Parameters

path string

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

cpioFormat CpioFormat

定义 cpio header 格式

Examples

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(流,CpioFormat,XzArchiveSettings)

存储存档以 xz 压缩到流。

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

Parameters

output Stream

目的地流

cpioFormat CpioFormat

定义 cpio header 格式

settings XzArchiveSettings

设置特定 xz 档案:字典大小,区块大小,检查类型。

Examples

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);
        }
    }
}

Remarks

流量必须是可写的。

Exceptions

ArgumentNullException

output’ is null.

ArgumentException

output’ is not writable.

SaveXzCompressed(字符串, CpioFormat, XzArchiveSettings)

通过 xz 压缩存储到路径的档案。

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

Parameters

path string

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

cpioFormat CpioFormat

定义 cpio header 格式

settings XzArchiveSettings

设置特定 xz 档案:字典大小,区块大小,检查类型。

Examples

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

SaveZ压缩(流量,CpioFormat)

通过 Z 压缩存储存档到流。

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

Parameters

output Stream

目的地流

cpioFormat CpioFormat

定义 cpio header 格式

Examples

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);
        }
    }
}

Remarks

必须是可写的。

Exceptions

ArgumentNullException

output’ is null.

ArgumentException

output’ is not writable.

SaveZ压缩(字符串,CpioFormat)

通过 Z 压缩存储到路径的档案。

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

Parameters

path string

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

cpioFormat CpioFormat

定义 cpio header 格式

Examples

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(流量,CpioFormat)

存储存档到流量,使用Zstandard压缩。

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

Parameters

output Stream

目的地流

cpioFormat CpioFormat

定义 cpio header 格式

Examples

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);
        }
    }
}

Remarks

必须是可写的。

Exceptions

ArgumentNullException

output’ is null.

ArgumentException

output’ is not writable.

SaveZstandard(字符串,CpioFormat)

通过 Zstandard 压缩将文件存储到文件中。

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

Parameters

path string

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

cpioFormat CpioFormat

定义 cpio header 格式

Examples

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");
    }
}
 中文