It does not appear to be a valid archive (Byte array to zip file in c#.net)

I am facing issue while converting byte array to zip file.Even though zip file is created using the below code but when I am extracting the zip file I am getting error "Cannot open file. It does not appear to be a valid archive".

private static void ShowZipFile(string fileName, byte[] data)
{
    byte[] compress = Compress(data);
    File.WriteAllBytes(fileName, compress);
}            

private static byte[] Compress(byte[] data)
{
    using (MemoryStream memory = new MemoryStream())
    {
        using (GZipStream gzip = new GZipStream(memory,
        CompressionMode.Compress, true))
        {
            gzip.Write(data, 0, data.Length);
        }
        return memory.ToArray();
    } 

}
Jon Skeet
people
quotationmark

A GZipStream isn't a zip file, basically - it's a gzip file. That's just compressed data, without any notions of multiple files, file names etc. If you save the file as foo.gz you may find that the zip tool you use knows how to decompress that, but you definitely need to understand that it's not the same as a foo.zip with file entries etc.

If you want to create an actual zip file, you might want to look at SharpZipLib, System.IO.Compression.ZipFile or similar libraries.

people

See more on this question at Stackoverflow