Q:

Problems decompressing a gzip archive in .NET

I grabbed the following code somewhere off the Internet, 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 doesn't 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;
}

What's wrong with the code that would cause this problem? 

A:

The problem is that the URL you specified in your question doesn't actually give a gzip file.  It takes the browser to a page where you select a mirror. 
If you temporarily change your Download method to use:
string text = wc. DownloadString(pUrl);
Console. WriteLine(text);

you'll see all the HTML for mirror selection. 
If you use a URL which is the actual gz file, e.g. http://wwwmaster.postgresql.org/redir/170/h/pgadmin3/release/v1.8.4/src/pgadmin3-1.8.4.tar.gz then it works fine.