Class Bzip2Archive
名称: Aspose.Zip.Bzip2 收藏: Aspose.Zip.dll (25.5.0)
此类代表 bzip2 档案文件. 使用它来编写或提取 bzip2 档案。
public class Bzip2Archive : IArchive, IDisposable, IArchiveFileEntry
Inheritance
Implements
IArchive , IDisposable , IArchiveFileEntry
继承人
object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Remarks
bzip2 压缩文件使用 Burrows-Wheeler 区块分文本压缩算法和 Huffman 编码. 查看更多: https://en.wikipedia.org/wiki/Bzip2
Constructors
Bzip2Archive()
启动一个新的例子 Aspose.Zip.Bzip2.Bzip2Archive 类准备压缩。
public Bzip2Archive()
Examples
下面的例子表明如何压缩文件。
using (Bzip2Archive archive = new Bzip2Archive())
{
archive.SetSource("data.bin");
archive.Save("archive.bz2");
}
Bzip2Archive(流量,Bzip2LoadOptions)
启动一个新的例子 Aspose.Zip.Bzip2.Bzip2Archive 类准备解压。
public Bzip2Archive(Stream sourceStream, Bzip2LoadOptions loadOptions = null)
Parameters
sourceStream
Stream
档案的来源。
loadOptions
Bzip2LoadOptions
与存档加载的选项。
Examples
从一个流中打开一个档案,然后将其提取到一个
var ms = new MemoryStream();
using (Bzip2Archive archive = new Bzip2Archive(File.OpenRead("archive.bz2")))
archive.Open().CopyTo(ms);
Remarks
此构建器不解压. 查看 Aspose.Zip.Bzip2.Bzip2Archive.Open 解压方法。
Exceptions
早流结束。
错误的签名比特
Bzip2Archive(字符串,Bzip2LoadOptions)
启动一个新的例子 Aspose.Zip.Bzip2.Bzip2Archive 类准备解压。
public Bzip2Archive(string path, Bzip2LoadOptions loadOptions = null)
Parameters
path
string
走向档案的路径。
loadOptions
Bzip2LoadOptions
与存档加载的选项。
Examples
从文件中按路径打开一个档案,然后将其提取到一个
var ms = new MemoryStream();
using (Bzip2Archive archive = new Bzip2Archive("archive.bz2"))
archive.Open().CopyTo(ms);
Remarks
此构建器不解压. 查看 Aspose.Zip.Bzip2.Bzip2Archive.Open 解压方法。
Exceptions
path’ is null.
召唤者没有所需的访问许可。
path’ 是空的,只包含白色空间,或包含无效的字符。
拒绝访问 path" 文件。
指定的 path’, 文件名, 或两者都超过系统定义的最大长度. 例如,在基于 Windows 的平台上,路径必须小于 248 个字符, 文件名必须小于 260 个字符。
文件在 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 (Bzip2Archive archive = new Bzip2Archive("archive.bz2"))
{
archive.Extract(httpResponseStream);
}
Exceptions
destination’ does not support writing.
Extract(线条)
通过路径将文件提取到文件中。
public FileInfo Extract(string path)
Parameters
path
string
路径到目的地文件. 如果文件已经存在,它将被过写。
Returns
获取的文件信息。
Exceptions
path’ is null.
召唤者没有所需的访问许可。
path’ 是空的,只包含白色空间,或包含无效的字符。
拒绝访问 path" 文件。
指定的 path’, 文件名, 或两者都超过系统定义的最大长度. 例如,在基于 Windows 的平台上,路径必须小于 248 个字符, 文件名必须小于 260 个字符。
文件在 path’ 中间包含一个列(:)。
文件未找到。
指定的路径是无效的,例如在无地图驱动器上。
文件已经开放了。
ExtractToDirectory(线条)
将档案内容提取到所提供的目录中。
public void ExtractToDirectory(string destinationDirectory)
Parameters
destinationDirectory
string
路径到目录将提取的文件插入。
Remarks
如果目录不存在,它将被创建。
Exceptions
destinationDirectory’ is null.
例如,在基于 Windows 的平台上,路径必须小于 248 个字符,文件名必须小于 260 个字符。
呼叫者没有必要的许可访问现有目录。
如果目录不存在,路径包含一个列符(:)不属于驱动标签(“C:”)的一部分。
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 (:).
路径指定的目录是一个文件. -or- 网络名称不明。
Open()
打开存档用于提取,并提供存档内容的流。
public Stream Open()
Returns
代表档案的内容的流。
Examples
使用:Stream decompressed = archive.Open();
.NET 4.0 或更高版本 - 使用 Stream.CopyTo 方法:decompressed.CopyTo(httpResponse.OutputStream)
.NET 3.5 和之前 - 手动复制比特:
byte[] buffer = new byte[8192];
int bytesRead;
while (0 < (bytesRead = decompressed.Read(buffer, 0, buffer.Length)))
fileStream.Write(buffer, 0, bytesRead);
```</p>
#### Remarks
Read from the stream to get the original content of the file. See examples section.
### <a id="Aspose_Zip_Bzip2_Bzip2Archive_Save_System_IO_Stream_Aspose_Zip_Bzip2_Bzip2SaveOptions_"></a> Save\(Stream, Bzip2SaveOptions\)
Saves archive to the stream provided.
```csharp
public void Save(Stream outputStream, Bzip2SaveOptions saveOptions = null)
Parameters
outputStream
Stream
目的地流
saveOptions
Bzip2SaveOptions
存储一个 bzip2 档案的选项. 如果没有指定,将使用 900 Kb 块大小。
Examples
将压缩数据写入 http 响应流。
using (var archive = new Bzip2Archive())
{
archive.SetSource(new FileInfo("data.bin"));
archive.Save(httpResponse.OutputStream);
}
Remarks
必须是可写的。
Exceptions
要存档的数据来源尚未提供。
outputStream’ is not writable.
文件源仅是阅读或是目录。
所指定的文件源路径是无效的,例如在无地图驱动器上。
文件源已经开放了。
Save(字符串,Bzip2SaveOptions)
存储存档到提供的目的地文件。
public void Save(string destinationFileName, Bzip2SaveOptions saveOptions = null)
Parameters
destinationFileName
string
要创建档案的路径 如果指定的文件名指向现有文件,则将重写。
saveOptions
Bzip2SaveOptions
存储一个 bzip2 档案的选项. 如果没有指定,将使用 900 Kb 块大小。
Examples
编写压缩数据到文件。
using (var archive = new Bzip2Archive())
{
archive.SetSource(new FileInfo("data.bin"));
archive.Save("data.bz2");
}
Exceptions
destinationFileName’ is null.
召唤者没有所需的访问许可。
destinationFileName’ 是空的,只包含白色空间,或包含无效的字符。
拒绝访问 destinationFileName’ 文件。
指定的 destinationFileName’, 文件名, 或两者都超过系统定义的最大长度. 例如,在基于 Windows 的平台上,路径必须小于 248 个字符,文件名必须小于 260 个字符。
文件在 destinationFileName’ 包含字符串中间的一个列(:)。
SetSource(Stream)
设置要压缩的内容在档案中。
public void SetSource(Stream source)
Parameters
source
Stream
存档的输入流。
Examples
using (Bzip2Archive archive = new Bzip2Archive())
{
archive.SetSource(new MemoryStream(new byte[] { 0x00,0xFF }));
archive.Save("archive.bz2");
}
SetSource(FileInfo)
设置要压缩的内容在档案中。
public void SetSource(FileInfo fileInfo)
Parameters
fileInfo
FileInfo
提到要压缩的文件。
Examples
using (Bzip2Archive archive = new Bzip2Archive())
{
archive.SetSource(new FileInfo("data.bin"));
archive.Save("archive.bz2");
}
SetSource(线条)
设置要压缩的内容在档案中。
public void SetSource(string path)
Parameters
path
string
文件要压缩的路径。
Examples
using (Bzip2Archive archive = new Bzip2Archive())
{
archive.SetSource("data.bin");
archive.Save("archive.bz2");
}
Exceptions
path’ is null.
召唤者没有所需的访问许可。
path’ 是空的,只包含白色空间,或包含无效的字符。
拒绝访问 path" 文件。
指定的 path’, 文件名, 或两者都超过系统定义的最大长度. 例如,在基于 Windows 的平台上,路径必须小于 248 个字符, 文件名必须小于 260 个字符。
文件在 path’ 中间包含一个列(:)。
SetSource(圖片來源:TarFormat)
设置要压缩的内容在档案中。
public void SetSource(TarArchive tarArchive, TarFormat format = TarFormat.UsTar)
Parameters
tarArchive
TarArchive
要压缩的档案。
format
TarFormat
定义 Tar Header 格式。
Examples
using (var tarArchive = new TarArchive())
{
tarArchive.CreateEntry("first.bin", "data1.bin");
tarArchive.CreateEntry("second.bin", "data2.bin");
using (var bzippedArchive = new Bzip2Archive())
{
bzippedArchive.SetSource(tarArchive);
bzippedArchive.Save("archive.tar.bz2");
}
}
Remarks
使用此方法组合共同 tar.bz2 档案。
SetSource(CpioArchive , CpioFormat)
设置要压缩的内容在档案中。
public void SetSource(CpioArchive cpioArchive, CpioFormat format = CpioFormat.OldAscii)
Parameters
cpioArchive
CpioArchive
Cpio 存档要压缩。
format
CpioFormat
定义 cpio header 格式
Examples
using (var cpioArchive = new CpioArchive())
{
cpioArchive.CreateEntry("first.bin", "data1.bin");
cpioArchive.CreateEntry("second.bin", "data2.bin");
using (var bzippedArchive = new Bzip2Archive())
{
bzippedArchive.SetSource(cpioArchive);
bzippedArchive.Save("archive.cpio.bz2");
}
}
Remarks
使用此方法组合共同的 cpio.bz2 档案。