我有两个文件(我使用7zip):n1.txt.gz和n2.txt.gz。然后,通过命令提示符将它们组合到文件n12.txt.gz:
type n1.txt.gz > n12.txt.gz
type n2.txt.gz >> n12.txt.gz如果我将文件n12.txt.gz解压缩为7zip,我将得到合并解压缩的原始文件(n1.txt + n2.txt)。但是如果我用这个代码
public static void Decompress2(String fileSource, String fileDestination, int buffsize)
{
using (var fsInput = new FileStream(fileSource, FileMode.Open, FileAccess.Read))
{
using (var fsOutput = new FileStream(fileDestination, FileMode.Create, FileAccess.Write))
{
using (var gzipStream = new GZipStream(fsInput, CompressionMode.Decompress))
{
var buffer = new Byte[buffsize];
int h;
while ((h = gzipStream.Read(buffer, 0, buffer.Length)) > 0)
{
fsOutput.Write(buffer, 0, h);
}
}
}
}
}我将只解压n12.txt.gz的第一部分,即解压缩n1.txt。
为什么GZipStream在合并文件的第一部分之后就停止了?7 7zip是如何解压缩整个文件的?
发布于 2016-03-20 13:36:52
GZipStream不实现从一个流解压缩多个文件的方法。
尝试使用处理ZIP存档(如DotNetZip )的库。
如果您完全愿意使用GZipStream,您可以在输入流中搜索gzip头,然后只向GZipStream提供属于每个文件的流的部分。
https://stackoverflow.com/questions/36114252
复制相似问题