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. C#
  4. GZipStream appears to malfunction (24K maximum)

GZipStream appears to malfunction (24K maximum)

Scheduled Pinned Locked Moved C#
csharpcomtutorialquestion
7 Posts 4 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.
  • P Offline
    P Offline
    Paladin2000
    wrote on last edited by
    #1

    I am getting an odd result when trying to decompress .gz files... The method that I am using only decompresses the first 24KB of the file, but the actual content is over 100 MB. I am using .NET 3.5, with the decompression method from the MSDN article (copied below). Has anyone seen this odd behavior before..?

    /// <summary>
    /// G-ZIP (.gz) Decompression method. Places new file in the same folder.
    /// </summary>
    /// <see cref="http://msdn2.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx"/>
    /// <param name="file">File to be decompressed.</param>
    private static void gDecompress(FileInfo file)
    {
    // Get the stream of the source file.
    using (FileStream inFile = file.OpenRead())
    {
    // Get original file extension, for example "doc" from report.doc.gz.
    string curFile = file.FullName;
    string origName = curFile.Remove(curFile.Length - file.Extension.Length);

        //Create the decompressed file.
        using (FileStream outFile = File.Create(origName))
        {
            using (GZipStream Decompress = new GZipStream(inFile, CompressionMode.Decompress))
            {
                //Copy the decompression stream into the output file.
                byte\[\] buffer = new byte\[4096\];
                int numRead;
                while ((numRead = Decompress.Read(buffer, 0, buffer.Length)) != 0)
                {
                    outFile.Write(buffer, 0, numRead);
                }
            }
        }
    }
    

    }

    L 2 Replies Last reply
    0
    • P Paladin2000

      I am getting an odd result when trying to decompress .gz files... The method that I am using only decompresses the first 24KB of the file, but the actual content is over 100 MB. I am using .NET 3.5, with the decompression method from the MSDN article (copied below). Has anyone seen this odd behavior before..?

      /// <summary>
      /// G-ZIP (.gz) Decompression method. Places new file in the same folder.
      /// </summary>
      /// <see cref="http://msdn2.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx"/>
      /// <param name="file">File to be decompressed.</param>
      private static void gDecompress(FileInfo file)
      {
      // Get the stream of the source file.
      using (FileStream inFile = file.OpenRead())
      {
      // Get original file extension, for example "doc" from report.doc.gz.
      string curFile = file.FullName;
      string origName = curFile.Remove(curFile.Length - file.Extension.Length);

          //Create the decompressed file.
          using (FileStream outFile = File.Create(origName))
          {
              using (GZipStream Decompress = new GZipStream(inFile, CompressionMode.Decompress))
              {
                  //Copy the decompression stream into the output file.
                  byte\[\] buffer = new byte\[4096\];
                  int numRead;
                  while ((numRead = Decompress.Read(buffer, 0, buffer.Length)) != 0)
                  {
                      outFile.Write(buffer, 0, numRead);
                  }
              }
          }
      }
      

      }

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Timothy CIAN wrote:

      Has anyone seen this odd behavior before..?

      I haven't. I did look into MSDN a bit, and I noticed the code examples for 2.0, 3.5, and 4.0 are all different, although I can't tell why; they all look good to me. [ADDED] I also ran the 2.0 example on a 1.5MB file, and all was well.[/ADDED] What makes you think the decompression terminates early? Are you sure the input file is what you intend it to be, maybe you are using similar code and it has a bug somewhere. I suggest you add (re-insert) debug statements, then compare the original uncompressed file size, the compressed one, and the final decompressed one. :)

      Luc Pattyn [My Articles] Nil Volentibus Arduum

      P 1 Reply Last reply
      0
      • L Luc Pattyn

        Timothy CIAN wrote:

        Has anyone seen this odd behavior before..?

        I haven't. I did look into MSDN a bit, and I noticed the code examples for 2.0, 3.5, and 4.0 are all different, although I can't tell why; they all look good to me. [ADDED] I also ran the 2.0 example on a 1.5MB file, and all was well.[/ADDED] What makes you think the decompression terminates early? Are you sure the input file is what you intend it to be, maybe you are using similar code and it has a bug somewhere. I suggest you add (re-insert) debug statements, then compare the original uncompressed file size, the compressed one, and the final decompressed one. :)

        Luc Pattyn [My Articles] Nil Volentibus Arduum

        P Offline
        P Offline
        Paladin2000
        wrote on last edited by
        #3

        Well, I have it attempting to decompress a collection of .gz files which are generated as output from a 3rd-party application. However, since I don't see anyone else (via Google search) having this problem, I shall assume it is either (1) something odd about how the 3rd-party source is (mis)creating .gz files, or (2) something is wonky elsewhere with the code. #2 seems unlikely, as this is a static method that only takes a FileInfo as input. It seems fairly self-contained. However, my next step is to create a tiny app that I can test this with (in better isolation from the "other stuff" in my code), as well as a parallel test using something like SharpZIPlib to see if there is any difference. Thanks...

        P 1 Reply Last reply
        0
        • P Paladin2000

          Well, I have it attempting to decompress a collection of .gz files which are generated as output from a 3rd-party application. However, since I don't see anyone else (via Google search) having this problem, I shall assume it is either (1) something odd about how the 3rd-party source is (mis)creating .gz files, or (2) something is wonky elsewhere with the code. #2 seems unlikely, as this is a static method that only takes a FileInfo as input. It seems fairly self-contained. However, my next step is to create a tiny app that I can test this with (in better isolation from the "other stuff" in my code), as well as a parallel test using something like SharpZIPlib to see if there is any difference. Thanks...

          P Offline
          P Offline
          Paladin2000
          wrote on last edited by
          #4

          Update... The .gz appears fine; I was able to extract it using WinZip (224 MB -> 877 MB). I tested Ionic's version of GZipStream, and it also resulted in a 24K file, along with the following error message: Destination array was not long enough. Check destIndex and length, and the array's lower bounds. Here is the Ionic-GZipStream version (which is almost identical to the previous):

          /// <summary>
          /// G-ZIP (.gz) Decompression method, using Ionic library. Places new file in the same folder.
          /// </summary>
          /// <param name="file">File to be decompressed.</param>
          private static void gDecompressIonic(FileInfo file)
          {
          // Get the stream of the source file.
          using (FileStream inFile = file.OpenRead())
          {
          // Get original file extension, for example "doc" from report.doc.gz.
          string curFile = file.FullName;
          string origName = curFile.Remove(curFile.Length - file.Extension.Length);

              //Create the decompressed file.
              using (FileStream outFile = File.Create(origName))
              {
                  using (Ionic.Zlib.GZipStream Decompress = new Ionic.Zlib.GZipStream(inFile, Ionic.Zlib.CompressionMode.Decompress))
                  {
                      //Copy the decompression stream into the output file.
                      byte\[\] buffer = new byte\[4096\];
                      int numRead;
                      while ((numRead = Decompress.Read(buffer, 0, buffer.Length)) != 0)
                      {
                          outFile.Write(buffer, 0, numRead);
                      }
                  }
              }
          }
          

          }

          J L 2 Replies Last reply
          0
          • P Paladin2000

            Update... The .gz appears fine; I was able to extract it using WinZip (224 MB -> 877 MB). I tested Ionic's version of GZipStream, and it also resulted in a 24K file, along with the following error message: Destination array was not long enough. Check destIndex and length, and the array's lower bounds. Here is the Ionic-GZipStream version (which is almost identical to the previous):

            /// <summary>
            /// G-ZIP (.gz) Decompression method, using Ionic library. Places new file in the same folder.
            /// </summary>
            /// <param name="file">File to be decompressed.</param>
            private static void gDecompressIonic(FileInfo file)
            {
            // Get the stream of the source file.
            using (FileStream inFile = file.OpenRead())
            {
            // Get original file extension, for example "doc" from report.doc.gz.
            string curFile = file.FullName;
            string origName = curFile.Remove(curFile.Length - file.Extension.Length);

                //Create the decompressed file.
                using (FileStream outFile = File.Create(origName))
                {
                    using (Ionic.Zlib.GZipStream Decompress = new Ionic.Zlib.GZipStream(inFile, Ionic.Zlib.CompressionMode.Decompress))
                    {
                        //Copy the decompression stream into the output file.
                        byte\[\] buffer = new byte\[4096\];
                        int numRead;
                        while ((numRead = Decompress.Read(buffer, 0, buffer.Length)) != 0)
                        {
                            outFile.Write(buffer, 0, numRead);
                        }
                    }
                }
            }
            

            }

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #5

            Timothy CIAN wrote:

            The .gz appears fine; I was able to extract it using WinZip

            Maybe the creator is using winzip rather than a gzip library. And winzip itself is doing something odd. Did you try a straight gzip utility?

            1 Reply Last reply
            0
            • P Paladin2000

              Update... The .gz appears fine; I was able to extract it using WinZip (224 MB -> 877 MB). I tested Ionic's version of GZipStream, and it also resulted in a 24K file, along with the following error message: Destination array was not long enough. Check destIndex and length, and the array's lower bounds. Here is the Ionic-GZipStream version (which is almost identical to the previous):

              /// <summary>
              /// G-ZIP (.gz) Decompression method, using Ionic library. Places new file in the same folder.
              /// </summary>
              /// <param name="file">File to be decompressed.</param>
              private static void gDecompressIonic(FileInfo file)
              {
              // Get the stream of the source file.
              using (FileStream inFile = file.OpenRead())
              {
              // Get original file extension, for example "doc" from report.doc.gz.
              string curFile = file.FullName;
              string origName = curFile.Remove(curFile.Length - file.Extension.Length);

                  //Create the decompressed file.
                  using (FileStream outFile = File.Create(origName))
                  {
                      using (Ionic.Zlib.GZipStream Decompress = new Ionic.Zlib.GZipStream(inFile, Ionic.Zlib.CompressionMode.Decompress))
                      {
                          //Copy the decompression stream into the output file.
                          byte\[\] buffer = new byte\[4096\];
                          int numRead;
                          while ((numRead = Decompress.Read(buffer, 0, buffer.Length)) != 0)
                          {
                              outFile.Write(buffer, 0, numRead);
                          }
                      }
                  }
              }
              

              }

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Does the file use Deflate64? WinZip handles that, but almost nothing else does.

              1 Reply Last reply
              0
              • P Paladin2000

                I am getting an odd result when trying to decompress .gz files... The method that I am using only decompresses the first 24KB of the file, but the actual content is over 100 MB. I am using .NET 3.5, with the decompression method from the MSDN article (copied below). Has anyone seen this odd behavior before..?

                /// <summary>
                /// G-ZIP (.gz) Decompression method. Places new file in the same folder.
                /// </summary>
                /// <see cref="http://msdn2.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx"/>
                /// <param name="file">File to be decompressed.</param>
                private static void gDecompress(FileInfo file)
                {
                // Get the stream of the source file.
                using (FileStream inFile = file.OpenRead())
                {
                // Get original file extension, for example "doc" from report.doc.gz.
                string curFile = file.FullName;
                string origName = curFile.Remove(curFile.Length - file.Extension.Length);

                    //Create the decompressed file.
                    using (FileStream outFile = File.Create(origName))
                    {
                        using (GZipStream Decompress = new GZipStream(inFile, CompressionMode.Decompress))
                        {
                            //Copy the decompression stream into the output file.
                            byte\[\] buffer = new byte\[4096\];
                            int numRead;
                            while ((numRead = Decompress.Read(buffer, 0, buffer.Length)) != 0)
                            {
                                outFile.Write(buffer, 0, numRead);
                            }
                        }
                    }
                }
                

                }

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                FWIW: I just finished a WinZip-like (but incompatible) utility based on System.IO.Compression.GZipStream and it perfectly decompresses files it compressed before, whatever the file size is (tried up to 2MB). Typical compression ratio is about 3 except of course for PDF, JPEG, and very small files. :)

                Luc Pattyn [My Articles] Nil Volentibus Arduum

                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