DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C# (http://www.daniweb.com/forums/forum61.html)
-   -   Decompress large file (http://www.daniweb.com/forums/thread196045.html)

jonnytabpni Jun 5th, 2009 6:47 pm
Decompress large file
 
Hi Folks,

I'm using this code I found online to decompress a large file. It works fine when I try it with a small file i.e. a 5MB mp3 (1.7MB compressed) but when I try and use it with a 250MB file (27MB compressed), the newly created output file is the same size as the input compressed file (AFAIK, it is probably a copy). I have tried this on a machine with 256MB of RAM and a machine with 4GB of RAM...

protected void Decompress(string filePath,string fileout)
        {
            FileStream sourceFile = File.OpenRead(filePath);
            FileStream destinationFile = File.Create(fileout);
            GZipStream unzip = null;
            byte[] buffer = new byte[sourceFile.Length];
            try
            {
                unzip = new GZipStream(sourceFile, CompressionMode.Decompress, false);
                int numberOfBytes = unzip.Read(buffer, 0, buffer.Length);

                destinationFile.Write(buffer, 0, numberOfBytes);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                sourceFile.Close();
                destinationFile.Close();
                unzip.Close();
            }
        }

Your help is appreciated.

Thanks

Tekmaven Jun 6th, 2009 12:00 am
Re: Decompress large file
 
Have you tried using the SharpZip? It's probably much better at handling compression. http://www.icsharpcode.net/OpenSource/SharpZipLib/


All times are GMT -4. The time now is 2:17 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC