using System.IO;
using System.IO.Compression;

namespace QsprMiscShared.Utilities;

public class FileCompressionUtility
{
	public static void CompressFile(string srcFileName, string destFileName)
	{
		FileInfo srcFile = new FileInfo(srcFileName);
		Compress(srcFile, CompressionMode.Compress, destFileName);
	}

	public static void DecompressFile(string srcFileName, string destFileName)
	{
		FileInfo srcFile = new FileInfo(srcFileName);
		Compress(srcFile, CompressionMode.Decompress, destFileName);
	}

	private static void Compress(FileInfo srcFile, CompressionMode mode, string destFileName)
	{
		using FileStream fileStream2 = srcFile.OpenRead();
		using FileStream fileStream = File.Create(destFileName);
		if (mode == CompressionMode.Compress)
		{
			using (GZipStream destination = new GZipStream(fileStream, mode))
			{
				fileStream2.CopyTo(destination);
				return;
			}
		}
		using GZipStream gZipStream = new GZipStream(fileStream2, mode);
		gZipStream.CopyTo(fileStream);
	}
}
