Class ZstandardArchive

Class ZstandardArchive

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

此类代表一个 Zstandard 档案文件. 使用它组成 Zstandard 档案。

public class ZstandardArchive : IArchive, IDisposable, IArchiveFileEntry

Inheritance

object ZstandardArchive

Implements

IArchive , IDisposable , IArchiveFileEntry

继承人

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

Constructors

ZstandardArchive()

启动一个新的例子 Aspose.Zip.Zstandard.Zstandard 档案类准备压缩。

public ZstandardArchive()

Examples

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

using (ZstandardArchive archive = new ZstandardArchive()) 
{
    archive.SetSource("data.bin");
    archive.Save("archive.zst");
}

ZstandardArchive(流量,ZstandardLoadOptions)

启动一个新的例子 Aspose.Zip.Zstandard.Zstandard 档案类准备解压。

public ZstandardArchive(Stream sourceStream, ZstandardLoadOptions options = null)

Parameters

sourceStream Stream

档案的来源。

options ZstandardLoadOptions

与存档加载的选项。

Examples

从一个流中打开一个档案,然后将其提取到一个

var ms = new MemoryStream();
using (GzipArchive archive = new ZstandardArchive(File.OpenRead("archive.zst")))
  archive.Open().CopyTo(ms);

Remarks

此构建器不解压. 查看 Aspose.Zip.Zstandard.ZstandardArchive.Open 解压方法。

ZstandardArchive(ZstandardLoadOptions 和 ZstandardLoad)

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

public ZstandardArchive(string path, ZstandardLoadOptions options = null)

Parameters

path string

走向档案的路径。

options ZstandardLoadOptions

与存档加载的选项。

Examples

从文件中按路径打开一个档案,然后将其提取到一个

var ms = new MemoryStream();
using (ZstandardArchive archive = new ZstandardArchive("archive.zst"))
  archive.Open().CopyTo(ms);

Remarks

此构建器不解压. 查看 Aspose.Zip.Zstandard.ZstandardArchive.Open 解压方法。

Exceptions

ArgumentNullException

path’ is null.

SecurityException

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

ArgumentException

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

UnauthorizedAccessException

拒绝访问 path" 文件。

PathTooLongException

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

NotSupportedException

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

Methods

Dispose()

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

public void Dispose()

Dispose(博尔)

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

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

管理的资源是否要消耗?

Extract(Stream)

将文件提取到提供的流。

public void Extract(Stream destination)

Parameters

destination Stream

目的地流,必须写作。

Examples

using (var archive = new GzipArchive("archive.zst"))
{
     archive.Extract(httpResponseStream);
}

Exceptions

ArgumentException

destination’ does not support writing.

Extract(线条)

通过路径将文件提取到文件中。

public FileInfo Extract(string path)

Parameters

path string

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

Returns

FileInfo

提取的文件的信息。

Exceptions

ArgumentNullException

path’ is null.

SecurityException

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

ArgumentException

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

UnauthorizedAccessException

拒绝访问 path" 文件。

PathTooLongException

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

NotSupportedException

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

ExtractToDirectory(线条)

将档案内容提取到所提供的目录中。

public void ExtractToDirectory(string destinationDirectory)

Parameters

destinationDirectory string

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

Remarks

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

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- 网络名称不明。

Open()

打开存档用于提取,并提供存档内容的流。

public Stream Open()

Returns

Stream

代表档案的内容的流。

Examples

提取档案并将提取的内容复制到文件流。

using (var archive = new ZstandardArchive("archive.zst"))
{
    using (var extracted = File.Create("data.bin"))
    {
        var unpacked = archive.Open();
        byte[] b = new byte[8192];
        int bytesRead;
        while (0 < (bytesRead = unpacked.Read(b, 0, b.Length)))
            extracted.Write(b, 0, bytesRead);
    }            
}

您可以使用 .NET 4.0 或更高版本的 Stream.CopyTo 方法: unpacked.Kopy To(提取);

Remarks

从流中阅读,以获取文件的原始内容。

Save(流量,ZstandardSaveOptions)

存储存档到提供的流量。

public void Save(Stream outputStream, ZstandardSaveOptions settings = null)

Parameters

outputStream Stream

目的地流

settings ZstandardSaveOptions

可选设置档案组成。

Examples

将压缩数据写入 http 响应流。

using (var archive = new ZstandardArchive()) 
{
    archive.SetSource(new FileInfo("data.bin"));
    archive.Save(httpResponse.OutputStream);
}

Remarks

必须是可写的。

Exceptions

ArgumentException

outputStream’ is not writable.

InvalidOperationException

源源未提供。

Save(字符串, ZstandardSaveOptions)

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

public void Save(string destinationFileName, ZstandardSaveOptions settings = null)

Parameters

destinationFileName string

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

settings ZstandardSaveOptions

可选设置档案组成。

Examples

using (var archive = new ZstandardArchive()) 
{
    archive.SetSource(new FileInfo("data.bin"));
    archive.Save("result.zst");
}

Exceptions

ArgumentNullException

destinationFileName’ is null.

SecurityException

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

ArgumentException

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

UnauthorizedAccessException

拒绝访问 destinationFileName’ 文件。

PathTooLongException

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

NotSupportedException

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

Save(FileInfo, ZstandardSaveOptions)

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

public void Save(FileInfo destination, ZstandardSaveOptions settings = null)

Parameters

destination FileInfo

FileInfo,将作为目的地流开放。

settings ZstandardSaveOptions

可选设置档案组成。

Examples

using (var archive = new ZstandardArchive()) 
{
    archive.SetSource(new FileInfo("data.bin"));
    archive.Save(new FileInfo("archive.zst"));
}

Exceptions

SecurityException

呼叫者没有必要的许可,以打开 目的地。

ArgumentException

文件路径是空的,或者只包含白色空间。

FileNotFoundException

文件未找到。

UnauthorizedAccessException

到文件的路径是阅读或是一个目录。

ArgumentNullException

destination’ is null.

DirectoryNotFoundException

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

IOException

文件已经开放了。

SetSource(Stream)

设置要压缩的内容在档案中。

public void SetSource(Stream source)

Parameters

source Stream

存档的输入流。

Examples

using (var archive = new ZstandardArchive())
{
    archive.SetSource(new MemoryStream(new byte[] { 0x00, 0xFF }));
    archive.Save("archive.zst");
}

SetSource(FileInfo)

设置要压缩的内容在档案中。

public void SetSource(FileInfo fileInfo)

Parameters

fileInfo FileInfo

提到要压缩的文件。

Examples

using (var archive = new ZstandardArchive()) 
{
    archive.SetSource(new FileInfo("data.bin"));
    archive.Save("archive.zst");
}

SetSource(线条)

设置要压缩的内容在档案中。

public void SetSource(string path)

Parameters

path string

文件要压缩的路径。

Examples

using (var archive = new ZstandardArchive()) 
{
    archive.SetSource("data.bin");
    archive.Save("archive.zst");
}

Exceptions

ArgumentNullException

path’ is null.

SecurityException

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

ArgumentException

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

UnauthorizedAccessException

拒绝访问 path" 文件。

PathTooLongException

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

NotSupportedException

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

 中文