mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-22 15:04:43 +00:00
add extract all test
This commit is contained in:
@@ -123,7 +123,7 @@ public static class ArchiveFactory
|
||||
)
|
||||
{
|
||||
using var archive = Open(sourceArchive);
|
||||
archive.WriteToDirectory(destinationDirectory, options);
|
||||
archive.ExtractToDirectory(destinationDirectory, options);
|
||||
}
|
||||
|
||||
private static T FindFactory<T>(FileInfo finfo)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Readers;
|
||||
@@ -22,17 +21,10 @@ public static class IArchiveExtensions
|
||||
using var reader = archive.ExtractAllEntries();
|
||||
reader.WriteAllToDirectory(destinationDirectory, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extracts the archive to the destination directory. Directories will be created as needed.
|
||||
/// </summary>
|
||||
/// <param name="archive">The archive to extract.</param>
|
||||
/// <param name="destination">The folder to extract into.</param>
|
||||
/// <param name="progressReport">Optional progress report callback.</param>
|
||||
/// <param name="cancellationToken">Optional cancellation token.</param>
|
||||
public static void ExtractToDirectory(
|
||||
this IArchive archive,
|
||||
string destination,
|
||||
ExtractionOptions? options = null,
|
||||
Action<double>? progressReport = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
@@ -74,8 +66,7 @@ public static class IArchiveExtensions
|
||||
}
|
||||
|
||||
// Write file
|
||||
using var fs = File.OpenWrite(path);
|
||||
entry.WriteTo(fs);
|
||||
entry.WriteToFile(path, options);
|
||||
|
||||
// Update progress
|
||||
bytesRead += entry.Size;
|
||||
|
||||
48
tests/SharpCompress.Test/ExtractAll.cs
Normal file
48
tests/SharpCompress.Test/ExtractAll.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Readers;
|
||||
using Xunit;
|
||||
|
||||
namespace SharpCompress.Test;
|
||||
|
||||
public class ExtractAll : TestBase
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("Zip.deflate.zip")]
|
||||
[InlineData("Rar5.rar")]
|
||||
[InlineData("Rar.rar")]
|
||||
[InlineData("Rar.solid.rar")]
|
||||
[InlineData( "7Zip.solid.7z")]
|
||||
[InlineData( "7Zip.nonsolid.7z")]
|
||||
[InlineData( "7Zip.LZMA.7z")]
|
||||
public async Task ExtractAllEntries(string archivePath)
|
||||
{
|
||||
|
||||
var testArchive = Path.Combine(TEST_ARCHIVES_PATH, archivePath);
|
||||
var options = new ExtractionOptions() {
|
||||
ExtractFullPath = true,
|
||||
Overwrite = true
|
||||
};
|
||||
|
||||
using var archive = ArchiveFactory.Open( testArchive );
|
||||
|
||||
if (archive.IsSolid && archive.Type != ArchiveType.SevenZip)
|
||||
{
|
||||
var reader = archive.ExtractAllEntries();
|
||||
while (await reader.MoveToNextEntryAsync())
|
||||
{
|
||||
if (!reader.Entry.IsDirectory)
|
||||
{
|
||||
await reader.WriteEntryToDirectoryAsync(SCRATCH_FILES_PATH, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
archive.ExtractToDirectory(SCRATCH_FILES_PATH, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user