public string Decompress(string filename)
{
StringBuilder result = null;
try
{
Stream s = new GZipInputStream(File.OpenRead(filename));
result = new StringBuilder(8192);
UTF7Encoding encoding = new UTF7Encoding(true);
int size = 2048;
byte[] writeData = new byte[2048];
while (true)
{
size = s.Read(writeData, 0, size);
if (size > 0)
{
result.Append(encoding.GetString(writeData,0,size));
}
else
{
break;
}
}
s.Close();
} // end try
catch (GZipException)
{
throw new Exception("Error: The file being read contains invalid data.");
}
catch (FileNotFoundException)
{
throw new Exception("Error:The file specified was not found.");
}
catch (ArgumentException)
{
throw new Exception("Error: path is a zero-length string, contains only white space, or contains one or more invalid characters");
}
catch (PathTooLongException)
{
throw new Exception("Error: The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.");
}
catch (DirectoryNotFoundException)
{
throw new Exception("Error: The specified path is invalid, such as being on an unmapped drive.");
}
catch (IOException)
{
throw new Exception("Error: An I/O error occurred while opening the file.");
}
catch (UnauthorizedAccessException)
{
throw new Exception("Error: path specified a file that is read-only, the path is a directory, or caller does not have the required permissions.");
}
return result.ToString();
}