none
Unzip file and wait for complete RRS feed

  • Question

  • I have large files that my Biztalk orchestrations downloads, they are .gz files. I have MSDN and GZipStream can be used to decompress. 

    Since these files are large,  I need some event notification mechanism to notify when the unzipping is complete. I want to avoid reading from a file which is currently under making during the Unzip process. Thanks 

    Wednesday, January 13, 2016 6:47 PM

Answers

  • Hi KKN79,

    I suggest you to take a look at the following code :

    public static readonly byte[] symbols = new byte[8 * 1024];
    
    public static void Decompress(FileInfo inFile, FileInfo outFile, double size, Action<double> progress)
    {
        var percents = new List<double>(100);
    
        using (var inStream = inFile.OpenRead())
        {
            using (var zipStream = new GZipStream(inStream, CompressionMode.Decompress))
            {
                using (var outStream = outFile.OpenWrite())
                {
                    var current = 0;
    
                    var total = 0;
                    while ((total = zipStream.Read(symbols, 0, symbols.Length)) != 0)
                    {
                        outStream.Write(symbols, 0, total);
                        current += total;
                        //Here report progress
                        var p = Math.Round(((double)current / size), 2) * 100;
                        if (!percents.Contains(p))
                        {
                            if (progress != null)
                            {
                                progress(p);
                            }
                            percents.Add(p);
                        }
                    }
                }
            }
        }
    }
    

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, January 14, 2016 5:45 AM