GZipStream不读整个文件 [英] GZipStream not reading the whole file

查看:179
本文介绍了GZipStream不读整个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码,下载gzip文件,并解压缩它们。问题是,我不能让它解压缩整个文件,只读取第一个4096字节,然后大约500多。

I have some code that downloads gzipped files, and decompresses them. The problem is, I can't get it to decompress the whole file, it only reads the first 4096 bytes and then about 500 more.

Byte[] buffer = new Byte[4096];
int count = 0;
FileStream fileInput = new FileStream("input.gzip", FileMode.Open, FileAccess.Read, FileShare.Read);
FileStream fileOutput = new FileStream("output.dat", FileMode.Create, FileAccess.Write, FileShare.None);
GZipStream gzipStream = new GZipStream(fileInput, CompressionMode.Decompress, true);

// Read from gzip steam
while ((count = gzipStream.Read(buffer, 0, buffer.Length)) > 0)
{
    // Write to output file
    fileOutput.Write(buffer, 0, count);
}

// Close the streams
...

我检查下载的文件;它是13MB压缩时,并包含一个XML文件。我手动解压缩的XML文件,内容都在那里。但是,当我使用此代码做,只输出XML文件的开始。

I've checked the downloaded file; it's 13MB when compressed, and contains one XML file. I've manually decompressed the XML file, and the content is all there. But when I do it with this code, it only outputs the very beginning of the XML file.

任何人有,为什么这可能发生的任何想法?

Anyone have any ideas why this might be happening?

推荐答案

我最终使用一个gzip可执行做减压,而不是一个GZipStream。它不能处理因某种原因该文件,但该可执行文件。

I ended up using a gzip executable to do the decompression instead of a GZipStream. It can't handle the file for some reason, but the executable can.

这篇关于GZipStream不读整个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆