private static void OnAddedEntry(object sender, BrZipArchiveEventArgs e) { var length = new FileInfo(e.FilePath).Length; var ratio = 100 * length / e.CompressedLength; // min is 1 Console.WriteLine("File " + e.FilePath + " was added. Length: " + length + " Compressed: " + e.CompressedLength + " Ratio: " + ratio + " %"); }
public virtual void AddDirectory(string directoryPath, string searchPattern = null, SearchOption searchOption = SearchOption.AllDirectories, Func <string, string, bool> includeFunc = null, Func <string, string, bool> excludeFunc = null, Func <string, string> nameFunc = null) { if (directoryPath == null) { throw new ArgumentNullException(nameof(directoryPath)); } searchPattern = searchPattern ?? "*.*"; directoryPath = Path.GetFullPath(directoryPath); foreach (var filePath in Directory.EnumerateFiles(directoryPath, searchPattern, searchOption)) { var relPath = filePath.Substring(directoryPath.Length + 1); if (excludeFunc != null && excludeFunc(filePath, relPath)) { continue; } if (includeFunc != null && !includeFunc(filePath, relPath)) { continue; } string name = null; if (nameFunc != null) { name = nameFunc(relPath); } name = name ?? relPath; var e = new BrZipArchiveEventArgs(name, 0, filePath, relPath); OnAddingEntry(this, e); if (e.Cancel) { continue; } // handle change of name if (e.Name != null && !string.Equals(e.Name, name, StringComparison.Ordinal)) { name = e.Name; } var len = AddEntry(filePath, name); OnAddedEntry(this, new BrZipArchiveEventArgs(name, len, filePath, relPath)); } }
protected virtual void OnAddingEntry(object sender, BrZipArchiveEventArgs e) => AddingEntry?.Invoke(sender, e);