I want to programmatically extract a zip file.
I searched google but I did not find it. I use this code, but I get this error
The magic number in the GZip header is incorrect. Make sure you are passing the gzip stream.
the code:
public static void Decompress(FileInfo fi) { using (FileStream inFile = fi.OpenRead()) { string curFile = fi.FullName; string origName = curFile.Remove(curFile.Length - fi.Extension.Length); using (FileStream outFile = File.Create(origName)) { using (GZipStream Decompress = new GZipStream(inFile, CompressionMode.Decompress)) { byte[] buffer = new byte[4096]; int numRead; while ((numRead = Decompress.Read(buffer, 0, buffer.Length)) != 0) { outFile.Write(buffer, 0, numRead); } Console.WriteLine("Decompressed: {0}", fi.Name); } } } }
It would be very nice if someone helped me.
Thanks in advance.
source share