public static void DecompressDirectory(string sCompressedFile, string sDir, ProgressDelegate progress) { if (!System.IO.Directory.Exists(sDir)) { System.IO.Directory.CreateDirectory(sDir); } using (FileStream inFile = new FileStream(sCompressedFile, FileMode.Open, FileAccess.Read, FileShare.None)) using (GZipStream zipStream = new GZipStream(inFile, CompressionMode.Decompress, true)) while (ZipUnzip.DecompressFile(sDir, zipStream, progress)) { ; } }
public static void CompressDirectory(string sInDir, string sOutFile, ProgressDelegate progress) { /* * if (!System.IO.Directory.Exists(sOutFile)) * System.IO.Directory.CreateDirectory(sOutFile); */ string[] sFiles = System.IO.Directory.GetFiles(sInDir, "*.*", SearchOption.AllDirectories); int iDirLen = sInDir[sInDir.Length - 1] == Path.DirectorySeparatorChar ? sInDir.Length : sInDir.Length + 1; using (FileStream outFile = new FileStream(sOutFile, FileMode.Create, FileAccess.Write, FileShare.None)) using (GZipStream str = new GZipStream(outFile, CompressionMode.Compress)) foreach (string sFilePath in sFiles) { string sRelativePath = sFilePath.Substring(iDirLen); if (progress != null) { progress(sRelativePath); } ZipUnzip.CompressFile(sInDir, sRelativePath, str); } }