Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Extracting .zip files

Extracting .zip files

Scheduled Pinned Locked Moved .NET (Core and Framework)
questioncsharp
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vipul Mehta
    wrote on last edited by
    #1

    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

    G S V R M 5 Replies Last reply
    0
    • V 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

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      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

      V 1 Reply Last reply
      0
      • V 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

        S Offline
        S Offline
        Shahar Gvirtz
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • G Giorgi Dalakishvili

          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

          V Offline
          V Offline
          Vipul Mehta
          wrote on last edited by
          #4

          Thanx for the links but I am suppose to use microsoft class liabraries only.

          Regards, Vipul Mehta

          1 Reply Last reply
          0
          • V 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

            V Offline
            V Offline
            Vipul Mehta
            wrote on last edited by
            #5

            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(); }

            1 Reply Last reply
            0
            • V 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

              R Offline
              R Offline
              rtalan
              wrote on last edited by
              #6

              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...

              V 1 Reply Last reply
              0
              • V 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

                M Offline
                M Offline
                Mike Dimmick
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • R rtalan

                  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...

                  V Offline
                  V Offline
                  Vipul Mehta
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups