Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add variants of FastZip.CreateZip that take filters as IScanFilter instead of strings #482

Merged
merged 1 commit into from
Aug 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion src/ICSharpCode.SharpZipLib/Zip/FastZip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,49 @@ public void CreateZip(Stream outputStream, string sourceDirectory, bool recurse,
/// <param name="directoryFilter">The <see cref="PathFilter">directory filter</see> to apply.</param>
/// <param name="leaveOpen">true to leave <paramref name="outputStream"/> open after the zip has been created, false to dispose it.</param>
public void CreateZip(Stream outputStream, string sourceDirectory, bool recurse, string fileFilter, string directoryFilter, bool leaveOpen)
{
var scanner = new FileSystemScanner(fileFilter, directoryFilter);
CreateZip(outputStream, sourceDirectory, recurse, scanner, leaveOpen);
}

/// <summary>
/// Create a zip file.
/// </summary>
/// <param name="zipFileName">The name of the zip file to create.</param>
/// <param name="sourceDirectory">The directory to source files from.</param>
/// <param name="recurse">True to recurse directories, false for no recursion.</param>
/// <param name="fileFilter">The <see cref="IScanFilter">file filter</see> to apply.</param>
/// <param name="directoryFilter">The <see cref="IScanFilter">directory filter</see> to apply.</param>
public void CreateZip(string zipFileName, string sourceDirectory,
bool recurse, IScanFilter fileFilter, IScanFilter directoryFilter)
{
CreateZip(File.Create(zipFileName), sourceDirectory, recurse, fileFilter, directoryFilter, false);
}

/// <summary>
/// Create a zip archive sending output to the <paramref name="outputStream"/> passed.
/// </summary>
/// <param name="outputStream">The stream to write archive data to.</param>
/// <param name="sourceDirectory">The directory to source files from.</param>
/// <param name="recurse">True to recurse directories, false for no recursion.</param>
/// <param name="fileFilter">The <see cref="IScanFilter">file filter</see> to apply.</param>
/// <param name="directoryFilter">The <see cref="IScanFilter">directory filter</see> to apply.</param>
/// <param name="leaveOpen">true to leave <paramref name="outputStream"/> open after the zip has been created, false to dispose it.</param>
public void CreateZip(Stream outputStream, string sourceDirectory, bool recurse, IScanFilter fileFilter, IScanFilter directoryFilter, bool leaveOpen = false)
{
var scanner = new FileSystemScanner(fileFilter, directoryFilter);
CreateZip(outputStream, sourceDirectory, recurse, scanner, leaveOpen);
}

/// <summary>
/// Create a zip archive sending output to the <paramref name="outputStream"/> passed.
/// </summary>
/// <param name="outputStream">The stream to write archive data to.</param>
/// <param name="sourceDirectory">The directory to source files from.</param>
/// <param name="recurse">True to recurse directories, false for no recursion.</param>
/// <param name="scanner">For performing the actual file system scan</param>
/// <remarks>The <paramref name="outputStream"/> is closed after creation.</remarks>
private void CreateZip(Stream outputStream, string sourceDirectory, bool recurse, FileSystemScanner scanner, bool leaveOpen)
{
NameTransform = new ZipNameTransform(sourceDirectory);
sourceDirectory_ = sourceDirectory;
Expand All @@ -390,7 +433,6 @@ public void CreateZip(Stream outputStream, string sourceDirectory, bool recurse,
}

outputStream_.UseZip64 = UseZip64;
var scanner = new FileSystemScanner(fileFilter, directoryFilter);
scanner.ProcessFile += ProcessFile;
if (this.CreateEmptyDirectories)
{
Expand Down
2 changes: 1 addition & 1 deletion test/ICSharpCode.SharpZipLib.Tests/Zip/FastZipHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ private void TestFileNames(IEnumerable<string> names)
nameCount++;
}

zippy.CreateZip(tempZip.Filename, tempDir.Fullpath, true, null, null);
zippy.CreateZip(tempZip.Filename, tempDir.Fullpath, true, null);

using (ZipFile z = new ZipFile(tempZip.Filename))
{
Expand Down