/// <summary>
/// Compresses the file at the given path. Returns the path to the
/// compressed file.
/// </summary>
/// <param name="path">The path to compress.</param>
/// <returns>The path of the compressed file.</returns>
public string Compress(string path)
{
string outputPath = String.Concat(path, ".gz");
if (File.Exists(outputPath))
{
File.Delete(outputPath);
}
using (FileStream fs = File.OpenRead(path))
{
using (FileStream output = File.Create(outputPath))
{
using (GZipStream gzip = new GZipStream(output, CompressionMode.Compress, CompressionLevel.BestCompression))
{
byte[] buffer = new byte[4096];
int count = 0;
while (0 < (count = fs.Read(buffer, 0, buffer.Length)))
{
gzip.Write(buffer, 0, count);
}
}
}
}
return outputPath;
}