mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-22 23:15:20 +00:00
fix tests that use extract all wrongly
This commit is contained in:
@@ -45,12 +45,10 @@ public static class IArchiveExtensions
|
||||
var seenDirectories = new HashSet<string>();
|
||||
|
||||
// Extract
|
||||
var entries = archive.ExtractAllEntries();
|
||||
while (entries.MoveToNextEntry())
|
||||
foreach (var entry in archive.Entries)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var entry = entries.Entry;
|
||||
if (entry.IsDirectory)
|
||||
{
|
||||
var dirPath = Path.Combine(destination, entry.Key.NotNull("Entry Key is null"));
|
||||
@@ -77,7 +75,7 @@ public static class IArchiveExtensions
|
||||
|
||||
// Write file
|
||||
using var fs = File.OpenWrite(path);
|
||||
entries.WriteEntryTo(fs);
|
||||
entry.WriteTo(fs);
|
||||
|
||||
// Update progress
|
||||
bytesRead += entry.Size;
|
||||
|
||||
@@ -40,6 +40,29 @@ public abstract class RarReader : AbstractReader<RarReaderEntry, RarVolume>
|
||||
|
||||
public override RarVolume? Volume => volume;
|
||||
|
||||
public static RarReader Open(string filePath, ReaderOptions? options = null)
|
||||
{
|
||||
filePath.CheckNotNullOrEmpty(nameof(filePath));
|
||||
return Open(new FileInfo(filePath), options);
|
||||
}
|
||||
|
||||
public static RarReader Open(FileInfo fileInfo, ReaderOptions? options = null)
|
||||
{
|
||||
options ??= new ReaderOptions { LeaveStreamOpen = false };
|
||||
return Open(fileInfo.OpenRead(), options);
|
||||
}
|
||||
|
||||
public static RarReader Open(IEnumerable<string> filePaths, ReaderOptions? options = null)
|
||||
{
|
||||
return Open(filePaths.Select(x => new FileInfo(x)), options);
|
||||
}
|
||||
|
||||
public static RarReader Open(IEnumerable<FileInfo> fileInfos, ReaderOptions? options = null)
|
||||
{
|
||||
options ??= new ReaderOptions { LeaveStreamOpen = false };
|
||||
return Open(fileInfos.Select(x => x.OpenRead()), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens a RarReader for Non-seeking usage with a single volume
|
||||
/// </summary>
|
||||
|
||||
@@ -9,6 +9,18 @@ namespace SharpCompress.Readers;
|
||||
|
||||
public static class ReaderFactory
|
||||
{
|
||||
public static IReader Open(string filePath, ReaderOptions? options = null)
|
||||
{
|
||||
filePath.CheckNotNullOrEmpty(nameof(filePath));
|
||||
return Open(new FileInfo(filePath), options);
|
||||
}
|
||||
|
||||
public static IReader Open(FileInfo fileInfo, ReaderOptions? options = null)
|
||||
{
|
||||
options ??= new ReaderOptions { LeaveStreamOpen = false };
|
||||
return Open(fileInfo.OpenRead(), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens a Reader for Non-seeking usage
|
||||
/// </summary>
|
||||
|
||||
@@ -255,16 +255,10 @@ public class ArchiveTests : ReaderTests
|
||||
protected void ArchiveExtractToDirectory(
|
||||
string testArchive,
|
||||
ReaderOptions? readerOptions = null
|
||||
) => ArchiveExtractToDirectory(ArchiveFactory.AutoFactory, testArchive, readerOptions);
|
||||
|
||||
protected void ArchiveExtractToDirectory(
|
||||
IArchiveFactory archiveFactory,
|
||||
string testArchive,
|
||||
ReaderOptions? readerOptions = null
|
||||
)
|
||||
{
|
||||
testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive);
|
||||
using (var archive = archiveFactory.Open(new FileInfo(testArchive), readerOptions))
|
||||
using (var archive = ArchiveFactory.Open(new FileInfo(testArchive), readerOptions))
|
||||
{
|
||||
archive.ExtractToDirectory(SCRATCH_FILES_PATH);
|
||||
}
|
||||
@@ -342,13 +336,12 @@ public class ArchiveTests : ReaderTests
|
||||
{
|
||||
testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive);
|
||||
using var archive = ArchiveFactory.Open(testArchive);
|
||||
using var reader = archive.ExtractAllEntries();
|
||||
while (reader.MoveToNextEntry())
|
||||
foreach (var entry in archive.Entries)
|
||||
{
|
||||
if (!reader.Entry.IsDirectory)
|
||||
if (!entry.IsDirectory)
|
||||
{
|
||||
var memory = new MemoryStream();
|
||||
reader.WriteEntryTo(memory);
|
||||
entry.WriteTo(memory);
|
||||
|
||||
memory.Position = 0;
|
||||
|
||||
|
||||
@@ -407,10 +407,16 @@ public class RarReaderTests : ReaderTests
|
||||
Path.Combine("exe", "test.exe"),
|
||||
}
|
||||
);
|
||||
using var archive = RarArchive.Open(
|
||||
Path.Combine(TEST_ARCHIVES_PATH, "Rar.multi.part01.rar")
|
||||
using var reader = RarReader.Open(
|
||||
[
|
||||
Path.Combine(TEST_ARCHIVES_PATH, "Rar.multi.part01.rar"),
|
||||
Path.Combine(TEST_ARCHIVES_PATH, "Rar.multi.part02.rar"),
|
||||
Path.Combine(TEST_ARCHIVES_PATH, "Rar.multi.part03.rar"),
|
||||
Path.Combine(TEST_ARCHIVES_PATH, "Rar.multi.part04.rar"),
|
||||
Path.Combine(TEST_ARCHIVES_PATH, "Rar.multi.part05.rar"),
|
||||
Path.Combine(TEST_ARCHIVES_PATH, "Rar.multi.part06.rar"),
|
||||
]
|
||||
);
|
||||
using var reader = archive.ExtractAllEntries();
|
||||
while (reader.MoveToNextEntry())
|
||||
{
|
||||
Assert.Equal(expectedOrder.Pop(), reader.Entry.Key);
|
||||
|
||||
@@ -734,8 +734,7 @@ public class ZipArchiveTests : ArchiveTests
|
||||
{
|
||||
var zipPath = Path.Combine(TEST_ARCHIVES_PATH, "Zip.uncompressed.zip");
|
||||
using var stream = File.OpenRead(zipPath);
|
||||
var archive = ArchiveFactory.Open(stream);
|
||||
var reader = archive.ExtractAllEntries();
|
||||
var reader = ReaderFactory.Open(stream);
|
||||
var entries = 0;
|
||||
while (reader.MoveToNextEntry())
|
||||
{
|
||||
@@ -763,8 +762,7 @@ public class ZipArchiveTests : ArchiveTests
|
||||
};
|
||||
var zipPath = Path.Combine(TEST_ARCHIVES_PATH, "Zip.uncompressed.zip");
|
||||
using var stream = File.OpenRead(zipPath);
|
||||
var archive = ArchiveFactory.Open(stream);
|
||||
var reader = archive.ExtractAllEntries();
|
||||
var reader = ReaderFactory.Open(stream);
|
||||
var x = 0;
|
||||
while (reader.MoveToNextEntry())
|
||||
{
|
||||
@@ -781,7 +779,7 @@ public class ZipArchiveTests : ArchiveTests
|
||||
var zipPath = Path.Combine(TEST_ARCHIVES_PATH, "Zip.UnicodePathExtra.zip");
|
||||
using (var stream = File.OpenRead(zipPath))
|
||||
{
|
||||
var archive = ArchiveFactory.Open(
|
||||
var reader = ReaderFactory.Open(
|
||||
stream,
|
||||
new ReaderOptions
|
||||
{
|
||||
@@ -791,13 +789,12 @@ public class ZipArchiveTests : ArchiveTests
|
||||
},
|
||||
}
|
||||
);
|
||||
var reader = archive.ExtractAllEntries();
|
||||
reader.MoveToNextEntry();
|
||||
Assert.Equal("궖귛궖귙귪궖귗귪궖귙_wav.frq", reader.Entry.Key);
|
||||
}
|
||||
using (var stream = File.OpenRead(zipPath))
|
||||
{
|
||||
var archive = ArchiveFactory.Open(
|
||||
var reader = ReaderFactory.Open(
|
||||
stream,
|
||||
new ReaderOptions
|
||||
{
|
||||
@@ -807,7 +804,6 @@ public class ZipArchiveTests : ArchiveTests
|
||||
},
|
||||
}
|
||||
);
|
||||
var reader = archive.ExtractAllEntries();
|
||||
reader.MoveToNextEntry();
|
||||
Assert.Equal("きょきゅんきゃんきゅ_wav.frq", reader.Entry.Key);
|
||||
}
|
||||
|
||||
@@ -383,11 +383,10 @@ public class ZipReaderTests : ReaderTests
|
||||
[Fact]
|
||||
public void Zip_Uncompressed_Encrypted_Read()
|
||||
{
|
||||
using var archive = ArchiveFactory.Open(
|
||||
using var reader = ReaderFactory.Open(
|
||||
Path.Combine(TEST_ARCHIVES_PATH, "Zip.none.encrypted.zip"),
|
||||
new ReaderOptions { Password = "test" }
|
||||
);
|
||||
using var reader = archive.ExtractAllEntries();
|
||||
reader.MoveToNextEntry();
|
||||
Assert.Equal("first.txt", reader.Entry.Key);
|
||||
Assert.Equal(199, reader.Entry.Size);
|
||||
|
||||
Reference in New Issue
Block a user