Willcode4cash

Decompress downloaded file

Sep 17th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. private static void Decompress(FileInfo fileToDecompress, bool overwrite = false)
  2. {
  3.     if ((File.Exists(fileToDecompress.FullName) && overwrite) ||
  4.          !File.Exists(fileToDecompress.FullName))
  5.     {
  6.         using (FileStream originalFileStream = fileToDecompress.OpenRead())
  7.         {
  8.             string currentFileName = fileToDecompress.FullName;
  9.             string newFileName = currentFileName.Remove(currentFileName.Length - fileToDecompress.Extension.Length);
  10.  
  11.             using (FileStream decompressedFileStream = File.Create(newFileName))
  12.             {
  13.                 using (GZipStream decompressionStream = new GZipStream(originalFileStream, CompressionMode.Decompress))
  14.                 {
  15.                     decompressionStream.CopyTo(decompressedFileStream);
  16.                 }
  17.             }
  18.         }
  19.     }
  20. }
Add Comment
Please, Sign In to add comment