1 Replies - 439 Views - Last Post: 04 May 2011 - 01:02 PM Rate Topic: -----

#1 musya   User is offline

  • D.I.C Lover
  • member icon

Reputation: 11
  • View blog
  • Posts: 1,012
  • Joined: 25-April 07

Compressing using gzip in .net

Posted 04 May 2011 - 12:50 PM

I have this function that i took from msdn and it compresses a file to a .gz format, however i have a list of files that need to be backed up, is there a way to read in all of those files and compress them to just one .gz file as oppose to one file at a time? Thank you

here is my function:
public static void CompressFiles(FileInfo fi)
        {
            // Get the stream of the source file.
            using (FileStream inFile = fi.OpenRead())
            {
                // Prevent compressing hidden and 
                // already compressed files.
                if ((File.GetAttributes(fi.FullName)
                    & FileAttributes.Hidden)
                    != FileAttributes.Hidden & fi.Extension != ".gz")
                {
                    // Create the compressed file.
                    using (FileStream outFile =
                                File.Create(workingDir + ".gz"))
                    {
                        using (GZipStream Compress =
                            new GZipStream(outFile,
                            CompressionMode.Compress))
                        {
                            // Copy the source file into 
                            // the compression stream.
                            inFile.CopyTo(Compress);

                            //MessageBox.Show("Compressed " + fi.Name + " from " + fi.Length.ToString() + " to " + outFile.Length.ToString() + " bytes.");
                        }
                    }
                }
            }
        }


Is This A Good Question/Topic? 0
  • +

Replies To: Compressing using gzip in .net

#2 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Compressing using gzip in .net

Posted 04 May 2011 - 01:02 PM

The built in gzip algorithm does not support containers, so no, that's really not possible. I'd suggest using #zipLib or another third party zipping library.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1