Skip to content
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
9 changes: 9 additions & 0 deletions src/SharpCompress/Archives/SevenZip/SevenZipArchive.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,13 @@ IAsyncEnumerable<SevenZipVolume> volumes

protected override ValueTask<IAsyncReader> CreateReaderForSolidExtractionAsync() =>
new(new SevenZipReader(ReaderOptions, this));

public override async ValueTask<bool> IsSolidAsync()
{
var entries = await EntriesAsync
.Where(x => !x.IsDirectory)
.ToListAsync()
.ConfigureAwait(false);
return entries.GroupBy(x => x.FilePart.Folder).Any(folder => folder.Skip(1).Any());
}
}
2 changes: 1 addition & 1 deletion src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected override IReader CreateReaderForSolidExtraction() =>
Entries
.Where(x => !x.IsDirectory)
.GroupBy(x => x.FilePart.Folder)
.Any(folder => folder.Count() > 1);
.Any(folder => folder.Skip(1).Any());

public override bool IsEncrypted => Entries.First(x => !x.IsDirectory).IsEncrypted;

Expand Down
23 changes: 21 additions & 2 deletions tests/SharpCompress.Test/SevenZip/SevenZipArchiveAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,33 @@ public async Task SevenZipArchive_PPMd_AsyncStreamExtraction()
VerifyFiles();
}

[Fact]
public async Task SevenZipArchive_TestSolidDetectionAsync()
{
await using var oneBlockSolidArchive = await SevenZipArchive.OpenAsyncArchive(
Path.Combine(TEST_ARCHIVES_PATH, "7Zip.solid.1block.7z")
);
Assert.True(await oneBlockSolidArchive.IsSolidAsync());

await using var solidArchive = await SevenZipArchive.OpenAsyncArchive(
Path.Combine(TEST_ARCHIVES_PATH, "7Zip.solid.7z")
);
Assert.True(await solidArchive.IsSolidAsync());

await using var nonSolidArchive = await SevenZipArchive.OpenAsyncArchive(
Path.Combine(TEST_ARCHIVES_PATH, "7Zip.nonsolid.7z")
);
Assert.False(await nonSolidArchive.IsSolidAsync());
}

[Fact]
public async Task SevenZipArchive_Solid_ExtractAllEntries_Contiguous_Async()
{
// This test verifies that solid archives iterate entries as contiguous streams
// rather than recreating the decompression stream for each entry
var testArchive = Path.Combine(TEST_ARCHIVES_PATH, "7Zip.solid.7z");
await using var archive = await SevenZipArchive.OpenAsyncArchive(testArchive);
Assert.True(((SevenZipArchive)archive).IsSolid);
Assert.True(await archive.IsSolidAsync());

await using var reader = await archive.ExtractAllEntriesAsync();
while (await reader.MoveToNextEntryAsync())
Expand All @@ -255,7 +274,7 @@ public async Task SevenZipArchive_Solid_VerifyStreamReuse()
// and not recreated for each entry in solid archives
var testArchive = Path.Combine(TEST_ARCHIVES_PATH, "7Zip.solid.7z");
await using var archive = await SevenZipArchive.OpenAsyncArchive(testArchive);
Assert.True(((SevenZipArchive)archive).IsSolid);
Assert.True(await archive.IsSolidAsync());

await using var reader = await archive.ExtractAllEntriesAsync();

Expand Down