I grabbed the following code somewhere off the net, and I am using it to decompress Gzip files, such as http://wwwmaster.postgresql.org/download/mirrors-ftp/pgadmin3/release/v1.8.4/src/pgadmin3-1.8.4.tar.gz but when I run It, I get an exception, stating that the magic number doesnt match.
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;
}
Can anyone help as to whats wrong with the code that would cause this problem?