Extracting .zip files
-
Hi Friends, Using .NET 2.0 how do I extract .zip file? It seems GZipStream does not go well. Is there any other class in .NET where in can be used to extract .zip file? Thanx in advance.
Regards, Vipul Mehta Sr. Software Engineer Accenture Services Pvt Ltd
-
Hi Friends, Using .NET 2.0 how do I extract .zip file? It seems GZipStream does not go well. Is there any other class in .NET where in can be used to extract .zip file? Thanx in advance.
Regards, Vipul Mehta Sr. Software Engineer Accenture Services Pvt Ltd
Did you search google or codeproject? These are some of the links returned by google: http://www.zip-compression.com/CSharp_Zip_Examples.asp http://www.icsharpcode.net/OpenSource/SharpZipLib/
#region signature my articles #endregion
-
Hi Friends, Using .NET 2.0 how do I extract .zip file? It seems GZipStream does not go well. Is there any other class in .NET where in can be used to extract .zip file? Thanx in advance.
Regards, Vipul Mehta Sr. Software Engineer Accenture Services Pvt Ltd
Hi, In the java.utils.zip include tools that should help JAVA developers in .NET But, one of the grate features there, that i can't understand why it isn't part of the common BCL is the zip file support. First, add vjslib.dll and vjslibcw.dll as reference. If you can't find them, ther are in J# Package: Here[^]. Use ZipFile Class to zip and unzip files.
-
Did you search google or codeproject? These are some of the links returned by google: http://www.zip-compression.com/CSharp_Zip_Examples.asp http://www.icsharpcode.net/OpenSource/SharpZipLib/
#region signature my articles #endregion
Thanx for the links but I am suppose to use microsoft class liabraries only.
Regards, Vipul Mehta
-
Hi Friends, Using .NET 2.0 how do I extract .zip file? It seems GZipStream does not go well. Is there any other class in .NET where in can be used to extract .zip file? Thanx in advance.
Regards, Vipul Mehta Sr. Software Engineer Accenture Services Pvt Ltd
Hi, After implementing the following logic I get "The magic number in GZip header is not correct. Make sure you are passing in a GZip stream." error string sourceFile = @"C:\Test\MyDocs.zip"; string destinationFile = @"C:\Test"; if (File.Exists(sourceFile) == false) { return; } FileStream sourceStream = null; FileStream destinationStream = null; GZipStream decompressedStream = null; byte[] quartetBuffer; int position; int checkLength; byte[] buffer; try { sourceStream = new FileStream(sourceFile, FileMode.Open); decompressedStream = new GZipStream(sourceStream, CompressionMode.Decompress, true); quartetBuffer = new Byte[4]; position = Convert.ToInt32(sourceStream.Length) - 4; sourceStream.Position = position; sourceStream.Read(quartetBuffer, 0, quartetBuffer.Length); sourceStream.Position = 0; checkLength = BitConverter.ToInt32(quartetBuffer, 0); buffer = new byte[checkLength + 100]; int offset = 0; int total = 0; while (true) { int bytesRead; bytesRead = decompressedStream.Read(buffer, offset, 100); if (bytesRead == 0) { break; } else { offset += bytesRead; total += bytesRead; } } // Now write everything to the destination file destinationStream = new FileStream(destinationFile, FileMode.Create); destinationStream.Write(buffer, 0, total); // and flush everyhting to clean out the buffer destinationStream.Flush(); } catch (Exception ex) { } finally { // Make sure we allways close all streams if (sourceStream != null) { sourceStream.Close(); } if (decompressedStream != null) { decompressedStream.Close(); }
-
Hi Friends, Using .NET 2.0 how do I extract .zip file? It seems GZipStream does not go well. Is there any other class in .NET where in can be used to extract .zip file? Thanx in advance.
Regards, Vipul Mehta Sr. Software Engineer Accenture Services Pvt Ltd
Are you absolutely sure your .zip file is in gzip format? The gzip format has a header and the GZipStream class accounts for this. But, if your .zip file is not in gzip format, the gzip decompression will not work. Your .zip file may have been created with the DEFLATE compression method in which case you need to use the DeflateStream class. Simply substitute GZipStream with DeflateStream and see what happens...
-
Hi Friends, Using .NET 2.0 how do I extract .zip file? It seems GZipStream does not go well. Is there any other class in .NET where in can be used to extract .zip file? Thanx in advance.
Regards, Vipul Mehta Sr. Software Engineer Accenture Services Pvt Ltd
ZIP is not GZip. They are different formats. GZip compresses a single stream of bytes, ZIP is a container for multiple files each of which can be compressed a different way (although conventionally the Deflate algorithm is used, unless that gives no compression in which case the original file is simply stored instead). The ZIP format is documented[^]. Parsing it is actually pretty easy. SharpZipLib does work but I've found it pretty slow. The GZipStream and DeflateStream classes are primarily intended for the web support e.g. HttpWebRequest, because the HTTP protocol allows responses to be compressed. Java has ZIP classes because its class library format, JAR, is simply a renamed ZIP file. (An individual class's bytecode is stored in a .class file, early versions of Java did not allow you to bundle these up into a package, later versions added the Java ARchive, JAR, format.)
DoEvents
: Generating unexpected recursion since 1991 -
Are you absolutely sure your .zip file is in gzip format? The gzip format has a header and the GZipStream class accounts for this. But, if your .zip file is not in gzip format, the gzip decompression will not work. Your .zip file may have been created with the DEFLATE compression method in which case you need to use the DeflateStream class. Simply substitute GZipStream with DeflateStream and see what happens...
I am trying to unzip an container .zip file (it contains many files & folder within that). My app. downloads this .zip file from an http URL of an web site & then tries to unzip it. After implementing DeflateStream class, it shows me following error: "Block length does not match with its complement"
Regards, Vipul Mehta