-
Notifications
You must be signed in to change notification settings - Fork 510
fix async 7z seeking #1200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix async 7z seeking #1200
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |||||||||||||||
| using System.Threading; | ||||||||||||||||
| using System.Threading.Tasks; | ||||||||||||||||
| using SharpCompress.Archives; | ||||||||||||||||
| using SharpCompress.Archives.SevenZip; | ||||||||||||||||
| using SharpCompress.Readers; | ||||||||||||||||
| using SharpCompress.Test.Mocks; | ||||||||||||||||
| using Xunit; | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -224,4 +226,95 @@ public async Task SevenZipArchive_PPMd_AsyncStreamExtraction() | |||||||||||||||
|
|
||||||||||||||||
| VerifyFiles(); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| [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 = SevenZipArchive.OpenAsyncArchive(testArchive); | ||||||||||||||||
| Assert.True(((SevenZipArchive)archive).IsSolid); | ||||||||||||||||
|
|
||||||||||||||||
| await using var reader = await archive.ExtractAllEntriesAsync(); | ||||||||||||||||
| while (await reader.MoveToNextEntryAsync()) | ||||||||||||||||
| { | ||||||||||||||||
| if (!reader.Entry.IsDirectory) | ||||||||||||||||
| { | ||||||||||||||||
| await reader.WriteEntryToDirectoryAsync(SCRATCH_FILES_PATH); | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| VerifyFiles(); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| [Fact] | ||||||||||||||||
| public async Task SevenZipArchive_Solid_VerifyStreamReuse() | ||||||||||||||||
| { | ||||||||||||||||
| // This test verifies that the folder stream is reused within each folder | ||||||||||||||||
| // and not recreated for each entry in solid archives | ||||||||||||||||
| var testArchive = Path.Combine(TEST_ARCHIVES_PATH, "7Zip.solid.7z"); | ||||||||||||||||
| await using var archive = SevenZipArchive.OpenAsyncArchive(testArchive); | ||||||||||||||||
| Assert.True(((SevenZipArchive)archive).IsSolid); | ||||||||||||||||
|
|
||||||||||||||||
| await using var reader = await archive.ExtractAllEntriesAsync(); | ||||||||||||||||
|
|
||||||||||||||||
| var sevenZipReader = Assert.IsType<SevenZipArchive.SevenZipReader>(reader); | ||||||||||||||||
| sevenZipReader.DiagnosticsEnabled = true; | ||||||||||||||||
|
|
||||||||||||||||
| Stream? currentFolderStreamInstance = null; | ||||||||||||||||
| object? currentFolder = null; | ||||||||||||||||
| var entryCount = 0; | ||||||||||||||||
| var entriesInCurrentFolder = 0; | ||||||||||||||||
| var streamRecreationsWithinFolder = 0; | ||||||||||||||||
|
|
||||||||||||||||
| while (await reader.MoveToNextEntryAsync()) | ||||||||||||||||
| { | ||||||||||||||||
| if (!reader.Entry.IsDirectory) | ||||||||||||||||
| { | ||||||||||||||||
| // Extract the entry to trigger GetEntryStream | ||||||||||||||||
| using var entryStream = await reader.OpenEntryStreamAsync(); | ||||||||||||||||
| var buffer = new byte[4096]; | ||||||||||||||||
| while (entryStream.Read(buffer, 0, buffer.Length) > 0) | ||||||||||||||||
| { | ||||||||||||||||
| // Read the stream to completion | ||||||||||||||||
| } | ||||||||||||||||
|
Comment on lines
+277
to
+281
|
||||||||||||||||
| var buffer = new byte[4096]; | |
| while (entryStream.Read(buffer, 0, buffer.Length) > 0) | |
| { | |
| // Read the stream to completion | |
| } | |
| // Read the stream to completion to exercise folder stream reuse behavior | |
| await entryStream.CopyToAsync(Stream.Null); |
Copilot
AI
Feb 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment to entryCount is useless, since its value is never read.
Copilot
AI
Feb 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment to folder is useless, since its value is never read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is using synchronous Read() instead of ReadAsync(). For an async test, this should use await entryStream.ReadAsync(buffer, 0, buffer.Length) to properly exercise the async code path. The current implementation may not fully test the async behavior that the test is designed to verify.