using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.IO;
using System.IO.Compression;
/// <summary>
///compressFile 的摘要说明
/// </summary>
public class compressFile
{
	public compressFile()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}
    public static void CompressFile(string sourceFile, string destinationFile)
    {
        if (!File.Exists(sourceFile)) throw new FileNotFoundException();
        using (FileStream sourceStream = new FileStream(sourceFile, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
        {
            byte[] buffer = new byte[sourceStream.Length];
            int checkCounter = sourceStream.Read(buffer, 0, buffer.Length);
            if (checkCounter != buffer.Length) throw new ApplicationException();
            using (FileStream destinationStream = new FileStream(destinationFile, FileMode.OpenOrCreate, FileAccess.Write))
            {
                using (GZipStream compressedStream = new GZipStream(destinationStream, CompressionMode.Compress, true))
                {
                    compressedStream.Write(buffer, 0, buffer.Length);
                }
            }
        }
    }
}
