我从 Internet 的某个地方抓取了以下代码,并使用它来解压缩 gzip 文件,例如http://wwwmaster.postgresql.org/download/mirrors-ftp/pgadmin3/release/v1.8.4/src/pgadmin3- 1.8.4.tar.gz,但是当我运行它时,我得到一个异常,指出幻数不匹配。
public byte[] Download(string pUrl) {
WebClient wc = new WebClient();
byte[] bytes = wc.DownloadData(pUrl);
return UnGzip(bytes, 0);
}
private static byte[] UnGzip(byte[] data, int start) {
int size = BitConverter.ToInt32(data, data.Length - 4);
byte[] uncompressedData = new byte[size];
MemoryStream memStream = new MemoryStream(data, start, (data.Length - start));
memStream.Position = 0;
GZipStream gzStream = new GZipStream(memStream, CompressionMode.Decompress);
try {
gzStream.Read(uncompressedData, 0, size);
} catch (Exception gzError) {
throw;
}
gzStream.Close();
return uncompressedData;
}
导致此问题的代码有什么问题?