gpt4 book ai didi

c# - GZipStream 没有读取整个文件

转载 作者:太空狗 更新时间:2023-10-29 19:40:09 25 4
gpt4 key购买 nike

我有一些代码可以下载 gzip 文件并解压缩它们。问题是,我无法让它解压缩整个文件,它只读取前 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 文件的开头部分。

有人知道为什么会发生这种情况吗?

最佳答案

编辑

尽量不要让 GZipStream 打开:

GZipStream gzipStream = new GZipStream(fileInput, CompressionMode.Decompress,  
false);

GZipStream gzipStream = new GZipStream(fileInput, CompressionMode.Decompress);

关于c# - GZipStream 没有读取整个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3068382/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com