/// <summary>快速压缩目录。</summary> /// <param name="dirName"></param> /// <param name="outputName"></param> public static void CompressDirectory(String dirName, String outputName = null) { if (String.IsNullOrEmpty(dirName)) { throw new ArgumentNullException(nameof(dirName)); } if (String.IsNullOrEmpty(outputName)) { outputName = Path.ChangeExtension(Path.GetFileName(dirName), ".zip"); } using var zf = new ZipFile(); zf.AddDirectory(dirName); zf.Write(outputName); }
/// <summary>快速压缩文件。</summary> /// <param name="fileName"></param> /// <param name="outputName"></param> public static void CompressFile(String fileName, String outputName = null) { if (String.IsNullOrEmpty(fileName)) { throw new ArgumentNullException(nameof(fileName)); } if (String.IsNullOrEmpty(outputName)) { outputName = Path.ChangeExtension(fileName, ".zip"); } using var zf = new ZipFile(); zf.AddFile(fileName); zf.Write(outputName); }