Class GzipArchive
名称: Aspose.Zip.Gzip 收藏: Aspose.Zip.dll (25.5.0)
此类代表一个 gzip 档案文件. 使用它来编写或提取 gzip 档案。
public class GzipArchive : 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
Gzip 压缩算法是基于 DEFLATE 算法,是 LZ77 和 Huffman 编码的组合。
Constructors
GzipArchive()
启动一个新的例子 Aspose.Zip.Gzip.GzipArchive 类准备压缩。
public GzipArchive()
Examples
下面的例子表明如何压缩文件。
using (GzipArchive archive = new GzipArchive())
{
archive.SetSource("data.bin");
archive.Save("archive.gz");
}
GzipArchive(波尔,波尔)
启动一个新的例子 Aspose.Zip.Gzip.GzipArchive 类准备解压。
public GzipArchive(Stream sourceStream, bool parseHeader = false)
Parameters
sourceStream
Stream
档案的来源。
parseHeader
bool
要么分散流标题,要找出属性,包括名称。
Examples
从一个流中打开一个档案,然后将其提取到一个
var ms = new MemoryStream();
using (GzipArchive archive = new GzipArchive(File.OpenRead("archive.gz")))
archive.Open().CopyTo(ms);
Remarks
此构建器不解压. 查看 Aspose.Zip.Gzip.GzipArchive.Open 解压方法。
Exceptions
sourceStream’ is null.
sourceStream’ is too short.
sourceStream’ 有错误的签名。
GzipArchive(布尔,布尔)
启动 Aspose.Zip.Gzip.GzipArchive 类的新例子。
public GzipArchive(string path, bool parseHeader = false)
Parameters
path
string
走向档案的路径。
parseHeader
bool
要么分散流标题,要找出属性,包括名称。
Examples
从文件中按路径打开一个档案,然后将其提取到一个
var ms = new MemoryStream();
using (GzipArchive archive = new GzipArchive("archive.gz"))
archive.Open().CopyTo(ms);
Remarks
此构建器不解压. 查看 Aspose.Zip.Gzip.GzipArchive.Open 解压方法。
Exceptions
path’ is null.
召唤者没有所需的访问许可。
path’ 是空的,只包含白色空间,或包含无效的字符。
拒绝访问 path" 文件。
指定的 path’, 文件名, 或两者都超过系统定义的最大长度. 例如,在基于 Windows 的平台上,路径必须小于 248 个字符, 文件名必须小于 260 个字符。
文件在 path’ 中间包含一个列(:)。
文件太短了。
文件中的数据有错误的签名。
Properties
Name
原始文件的名称。
public string Name { get; }
财产价值
UncompressedSize
收到原始文件的尺寸。
public ulong UncompressedSize { get; }
财产价值
Remarks
如果未压缩的文件大小超过4GB,该属性将因头部中的32位限制而提供错误值。
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.gz"))
{
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
提取档案并将提取的内容复制到文件流。
using (var archive = new GzipArchive("archive.gz"))
{
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(Stream)
存储存档到提供的流量。
public void Save(Stream outputStream)
Parameters
outputStream
Stream
目的地流
Examples
将压缩数据写入 http 响应流。
using (var archive = new GzipArchive())
{
archive.SetSource(new FileInfo("data.bin"));
archive.Save(httpResponse.OutputStream);
}
Remarks
必须是可写的。
Exceptions
outputStream’ is not writable.
源源未提供。
Save(线条)
存储到所提供的目的地文件的档案。
public void Save(string destinationFileName)
Parameters
destinationFileName
string
要创建档案的路径 如果指定的文件名指向现有文件,则将重写。
Examples
using (var archive = new GzipArchive())
{
archive.SetSource("data.bin");
archive.Save("archive.gz");
}
Exceptions
destinationFileName’ is null.
召唤者没有所需的访问许可。
destinationFileName’ 是空的,只包含白色空间,或包含无效的字符。
拒绝访问 destinationFileName’ 文件。
指定的 destinationFileName’, 文件名, 或两者都超过系统定义的最大长度. 例如,在基于 Windows 的平台上,路径必须小于 248 个字符,文件名必须小于 260 个字符。
文件在 destinationFileName’ 包含字符串中间的一个列(:)。
SetSource(Stream)
设置要压缩的内容在档案中。
public void SetSource(Stream source)
Parameters
source
Stream
存档的输入流。
Examples
using (var archive = new GzipArchive())
{
archive.SetSource(new MemoryStream(new byte[] { 0x00, 0xFF }));
archive.Save("archive.gz");
}
SetSource(FileInfo)
设置要压缩的内容在档案中。
public void SetSource(FileInfo fileInfo)
Parameters
fileInfo
FileInfo
提到要压缩的文件。
Examples
using (var archive = new GzipArchive())
{
archive.SetSource(new FileInfo("data.bin"));
archive.Save("archive.gz");
}
SetSource(线条)
设置要压缩的内容在档案中。
public void SetSource(string path)
Parameters
path
string
文件要压缩的路径。
Examples
从文件中按路径打开一个档案,然后将其提取到一个
using (var archive = new GzipArchive())
{
archive.SetSource("data.bin");
archive.Save("archive.gz");
}
Exceptions
path’ is null.
召唤者没有所需的访问许可。
path’ 是空的,只包含白色空间,或包含无效的字符。
拒绝访问 path" 文件。
指定的 path’, 文件名, 或两者都超过系统定义的最大长度. 例如,在基于 Windows 的平台上,路径必须小于 248 个字符, 文件名必须小于 260 个字符。
文件在 path’ 中间包含一个列(:)。
SetSource(TarArchive)
设置要压缩的内容在档案中。
public void SetSource(TarArchive tarArchive)
Parameters
tarArchive
TarArchive
要压缩的档案。
Examples
using (var tarArchive = new TarArchive())
{
tarArchive.CreateEntry("first.bin", "data1.bin");
tarArchive.CreateEntry("second.bin", "data2.bin");
using (var gzippedArchive = new GzipArchive())
{
gzippedArchive.SetSource(tarArchive);
gzippedArchive.Save("archive.tar.gz");
}
}
Remarks
使用此方法组合共同 tar.gz 档案。