1

I am decompressing .gz files in-memory using SevenZipSharp libary in c# and have encountered a strange behavior where the file size grew by 2-3 times, the decompression took significantly longer. More specifically, the avg size of .gz files are around 40MB (700-800MB when decompressed) and the decompression time was in the order of tens of seconds at most. But it took more than half an hour to decompress this specific .gz file with 90MB size (1.6GB when decompressed). Each .gz file was orginally compressed from a single txt file via 7-zip. I have attached the code:

        for (int i = 0; i < fileNames.Length; i++)
        {
            using (FileStream fs = File.OpenRead(fileNames[i]))
            {
                using (var sze = new SevenZip.SevenZipExtractor(fs))                    
                {
                    MemoryStream mem = new MemoryStream();

                    sze.ExtractFile(0, mem);

                    using (StreamReader sr = new StreamReader(mem))
                    {
                        // do something
                    }
                }
             }
         }

Any idea why the decompression time exploded here? Is this just from the overhead associated with resizing of memory stream?

usr8
  • 11
  • 2
  • I would test it by wrapping your `MemoryStream` in a `using` statement. The OS may be taking its sweet time trying to find more memory for you. – TyCobb Nov 28 '13 at 04:08
  • I tried it, but it didn't solve the problem. Dispose() gets called on memory stream anyways when the control leaves the using block for StreamReader although as u mentioned, probably it's better practice. – usr8 Nov 28 '13 at 07:19

0 Answers0