Skip to content

Commit d80d966

Browse files
committed
Add variants of FastZip.CreateZip that take filters as IScanFilter instead of strings
1 parent 24f948a commit d80d966

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/ICSharpCode.SharpZipLib/Zip/FastZip.cs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,49 @@ public void CreateZip(Stream outputStream, string sourceDirectory, bool recurse,
375375
/// <param name="directoryFilter">The <see cref="PathFilter">directory filter</see> to apply.</param>
376376
/// <param name="leaveOpen">true to leave <paramref name="outputStream"/> open after the zip has been created, false to dispose it.</param>
377377
public void CreateZip(Stream outputStream, string sourceDirectory, bool recurse, string fileFilter, string directoryFilter, bool leaveOpen)
378+
{
379+
var scanner = new FileSystemScanner(fileFilter, directoryFilter);
380+
CreateZip(outputStream, sourceDirectory, recurse, scanner, leaveOpen);
381+
}
382+
383+
/// <summary>
384+
/// Create a zip file.
385+
/// </summary>
386+
/// <param name="zipFileName">The name of the zip file to create.</param>
387+
/// <param name="sourceDirectory">The directory to source files from.</param>
388+
/// <param name="recurse">True to recurse directories, false for no recursion.</param>
389+
/// <param name="fileFilter">The <see cref="IScanFilter">file filter</see> to apply.</param>
390+
/// <param name="directoryFilter">The <see cref="IScanFilter">directory filter</see> to apply.</param>
391+
public void CreateZip(string zipFileName, string sourceDirectory,
392+
bool recurse, IScanFilter fileFilter, IScanFilter directoryFilter)
393+
{
394+
CreateZip(File.Create(zipFileName), sourceDirectory, recurse, fileFilter, directoryFilter, false);
395+
}
396+
397+
/// <summary>
398+
/// Create a zip archive sending output to the <paramref name="outputStream"/> passed.
399+
/// </summary>
400+
/// <param name="outputStream">The stream to write archive data to.</param>
401+
/// <param name="sourceDirectory">The directory to source files from.</param>
402+
/// <param name="recurse">True to recurse directories, false for no recursion.</param>
403+
/// <param name="fileFilter">The <see cref="IScanFilter">file filter</see> to apply.</param>
404+
/// <param name="directoryFilter">The <see cref="IScanFilter">directory filter</see> to apply.</param>
405+
/// <param name="leaveOpen">true to leave <paramref name="outputStream"/> open after the zip has been created, false to dispose it.</param>
406+
public void CreateZip(Stream outputStream, string sourceDirectory, bool recurse, IScanFilter fileFilter, IScanFilter directoryFilter, bool leaveOpen = false)
407+
{
408+
var scanner = new FileSystemScanner(fileFilter, directoryFilter);
409+
CreateZip(outputStream, sourceDirectory, recurse, scanner, leaveOpen);
410+
}
411+
412+
/// <summary>
413+
/// Create a zip archive sending output to the <paramref name="outputStream"/> passed.
414+
/// </summary>
415+
/// <param name="outputStream">The stream to write archive data to.</param>
416+
/// <param name="sourceDirectory">The directory to source files from.</param>
417+
/// <param name="recurse">True to recurse directories, false for no recursion.</param>
418+
/// <param name="scanner">For performing the actual file system scan</param>
419+
/// <remarks>The <paramref name="outputStream"/> is closed after creation.</remarks>
420+
private void CreateZip(Stream outputStream, string sourceDirectory, bool recurse, FileSystemScanner scanner, bool leaveOpen)
378421
{
379422
NameTransform = new ZipNameTransform(sourceDirectory);
380423
sourceDirectory_ = sourceDirectory;
@@ -390,7 +433,6 @@ public void CreateZip(Stream outputStream, string sourceDirectory, bool recurse,
390433
}
391434

392435
outputStream_.UseZip64 = UseZip64;
393-
var scanner = new FileSystemScanner(fileFilter, directoryFilter);
394436
scanner.ProcessFile += ProcessFile;
395437
if (this.CreateEmptyDirectories)
396438
{

test/ICSharpCode.SharpZipLib.Tests/Zip/FastZipHandling.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ private void TestFileNames(IEnumerable<string> names)
238238
nameCount++;
239239
}
240240

241-
zippy.CreateZip(tempZip.Filename, tempDir.Fullpath, true, null, null);
241+
zippy.CreateZip(tempZip.Filename, tempDir.Fullpath, true, null);
242242

243243
using (ZipFile z = new ZipFile(tempZip.Filename))
244244
{

0 commit comments

Comments
 (0)