Skip to content

Commit

Permalink
Add variants of FastZip.CreateZip that take filters as IScanFilter in…
Browse files Browse the repository at this point in the history
…stead of strings
  • Loading branch information
Numpsy committed Aug 8, 2020
1 parent 24f948a commit d80d966
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
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

0 comments on commit d80d966

Please sign in to comment.