111,098
社区成员




/// <summary>
/// 压缩
/// </summary>
/// <param name="filePath">文件路径</param>
/// <param name="zipPath">压缩文件路径</param>
public static void Compress(string filePath, string zipPath)
{
FileStream sourceFile = File.OpenRead(filePath);
FileStream destinationFile = File.Create(zipPath);
byte[] buffer = new byte[sourceFile.Length];
GZipStream zip = null;
try
{
sourceFile.Read(buffer, 0, buffer.Length);
zip = new GZipStream(destinationFile, CompressionMode.Compress);
zip.Write(buffer, 0, buffer.Length);
}
catch
{
throw;
}
finally
{
zip.Close();
sourceFile.Close();
destinationFile.Close();
}
}