Skip to content

Instantly share code, notes, and snippets.

@talkingdotnet
Created February 27, 2018 05:47
Show Gist options
  • Save talkingdotnet/6574f4262a51e116e1860a65155d54e7 to your computer and use it in GitHub Desktop.
Save talkingdotnet/6574f4262a51e116e1860a65155d54e7 to your computer and use it in GitHub Desktop.
private string UnZipFile(string filePath)
{
string unZippedFileName = "";
FileInfo fileToDecompress = new FileInfo(filePath);
try
{
using (FileStream originalFileStream = fileToDecompress.OpenRead())
{
string currentFileName = fileToDecompress.FullName;
unZippedFileName = currentFileName.Remove(currentFileName.Length - fileToDecompress.Extension.Length);
using (FileStream decompressedFileStream = File.Create(unZippedFileName))
{
using (GZipStream decompressionStream = new GZipStream(originalFileStream, CompressionMode.Decompress))
{
decompressionStream.CopyTo(decompressedFileStream);
}
}
}
WriteToConsole("File unzipped successfully.");
}
catch (Exception ex)
{
WriteToConsole("Error: DecompressFile()" + "\n" + ex.ToString());
unZippedFileName = "";
}
return unZippedFileName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment