SharpZipLib icon indicating copy to clipboard operation
SharpZipLib copied to clipboard

feat(fastzip): allow custom filesystemscanner

Open piksel opened this issue 4 years ago • 1 comments

Fixes #676

Or rather, allows it to be handled with a derived class:

  new FastZip().CreateZip(outStream, srcDir, recurse: true, new CustomFileSystemScanner(filter), leaveOpen: true);
class CustomFileSystemScanner:  FileSystemScanner 
{
	static IEnumerable<string> FixupNet5Enumeration(IEnumerable<string> items)
		=> items
			.Select(t => t.TrimEnd('\0'))
			.Where(t => {
				var itemName = Path.GetFileName(t);
				return itemName != "." && itemName != "..";
			});

	protected override IEnumerable<string> GetDirectories(string directory) 
		=> FixupNet5Enumeration(base.GetDirectories(directory));

	protected override IEnumerable<string> GetFiles(string directory) 
		=> FixupNet5Enumeration(base.GetFiles(directory));

	public CustomFileSystemScanner(string ff): base(ff) {}
	public CustomFileSystemScanner(string ff, string df): base(ff, df) {}
	public CustomFileSystemScanner(IScanFilter ff): base(ff){}
	public CustomFileSystemScanner(IScanFilter ff, IScanFilter df) : base(ff, df) {}
}

I certify that I own, and have sufficient rights to contribute, all source code and related material intended to be compiled or integrated with the source code for the SharpZipLib open source product (the "Contribution"). My Contribution is licensed under the MIT License.

piksel avatar Oct 22 '21 10:10 piksel

Codecov Report

Merging #678 (14cdc85) into master (612969e) will increase coverage by 0.10%. The diff coverage is 54.05%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #678      +/-   ##
==========================================
+ Coverage   73.79%   73.90%   +0.10%     
==========================================
  Files          68       68              
  Lines        8332     8301      -31     
==========================================
- Hits         6149     6135      -14     
+ Misses       2183     2166      -17     
Impacted Files Coverage Δ
.../ICSharpCode.SharpZipLib/Core/FileSystemScanner.cs 49.50% <44.44%> (+0.76%) :arrow_up:
src/ICSharpCode.SharpZipLib/Zip/FastZip.cs 59.78% <80.00%> (+0.61%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 612969e...14cdc85. Read the comment docs.

codecov[bot] avatar Oct 22 '21 10:10 codecov[bot]