我有一些下载并解压缩gzipped文件的代码。问题是,我无法将其完全解压缩,它只读取前4096个字节,然后大约还有500个字节。
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文件的开头部分。请问有人知道为什么会发生这种情况吗?