A robust .NET library offering a fluent API for efficient processing of files within zip archives.
$ dotnet add package ArchiveFlowArchiveFlow is a Fluent API for streamlined and efficient processing of zipped and unzipped file archives. It lets you focus on processing logic instead of file/zip handling code.
To use ArchiveFlow in your project, add the following package to your dependencies:
dotnet add package ArchiveFlow
Here's a a simple example to get you started with ArchiveFlow. This will process all files as text file in archive files in the specified folder. The default behaviour is to process all entries in archive files in the folder (non-recursive), and ignore non archive files.
var builder = new FileProcessorBuilder()
.FromFolder("./your/path")
.ProcessAsText((f, t) =>
{
// Your text processing logic here
})
builder.Build().ProcessFiles();
Here's an example that is a bit more advanced. It reads all xml files in the specified folder, recursively, including archives younger than 10 days, and processes the text as xml. It also sets the maximum degree of parallelism to the number of processors on the machine, and handles exceptions for corrupted zip files.
// use a concurrent dictionary beacuse we are using multiple threads
var dict = new ConcurrentDictionary<string, byte>();
var builder = new FileProcessorBuilder()
.FromFolder("/folder/with/xmlfiles_archived_or_not", FolderSelect.RootAndSubFolders)
.SetArchiveSearch(ArchiveSearch.SearchInAndOutsideArchives)
.FromZipWhere((z) => z.LastModified > DateTime.Now.AddDays(-10))
.WhereFile((f) => !f.FileName.Contains("ReturnValue"))
.ProcessAsText((f, t) =>
{
XDocument xdoc = XDocument.Parse(t);
(string? id, string? name) =
(xdoc.Descendants("Id").FirstOrDefault()?.Value,
xdoc.Descendants("Name").FirstOrDefault()?.Value);
dict.TryAdd($"{id}_{name}", 0);
})
.WithMaxDegreeOfParallelism(Environment.ProcessorCount)
.HandleExceptionWith((f, ex) =>
{
if (f.Extension == ".zip" && ex is InvalidOperationException)
{
// ignore these exceptions for zip files (corrupted zip)
return true;
}
return false;
});
builder.Build().ProcessFiles();
check out this fiddle for a working example: https://dotnetfiddle.net/sIwHrW
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)Distributed under the MIT License.
Dominique Biesmans - https://www.linkedin.com/in/dominiquebiesmans/
Project Link: https://github.com/domibies/archive-flow