Fix SevenZipReader to maintain contiguous stream state for solid archives#1172
Conversation
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
|
@copilot do more to test that it's the same contiguous stream. Should something be checked in the test to ensure it is for a solid stream or reader? |
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Added a comprehensive test
This definitively proves the stream is reused sequentially within each folder, not recreated per entry. Commit: 3c87242 |
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (2 files)
|
There was a problem hiding this comment.
Pull request overview
This PR restores contiguous streaming behavior for solid 7z archives by reusing a shared decoder stream per folder and adds targeted tests to prevent regressions.
Changes:
- Refactors
SevenZipArchive.SevenZipReaderto maintain a shared_currentFolderStreamper folder and expose internal diagnostics for testing. - Adjusts
GetEntryStreamto create a folder stream once and serve each entry via a boundedReadOnlySubStreamwrapped inSyncOnlyStream. - Adds solid-archive tests to verify contiguous extraction and to assert that the folder stream is reused rather than recreated, and updates test package locks to include
Mono.Posix.NETStandard.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs |
Implements per-folder shared decoder stream, exposes diagnostics properties on SevenZipReader, and disposes the shared folder stream correctly on folder transitions and reader disposal. |
tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs |
Adds regression tests for solid 7z contiguous extraction and for verifying that the internal folder stream is reused rather than recreated within a folder. |
tests/SharpCompress.Test/packages.lock.json |
Adds Mono.Posix.NETStandard as a direct dependency for applicable test target frameworks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
SevenZipReader was recreating the decompression stream for each entry in solid archives (where multiple files share a compressed stream), breaking the sequential read requirement and causing data corruption and performance issues.
Changes
_currentFolderStreamand_currentFolderfields toSevenZipReaderReadOnlySubStreambounded by entry sizeImplementation
Testing
SevenZipArchive_Solid_ExtractAllEntries_Contiguousverifies that solid archives can be extracted successfully using the readerSevenZipArchive_Solid_VerifyStreamReuseuses reflection to access private fields and verify that:streamRecreationsWithinFolder == 0)This definitively proves the contiguous streaming behavior has been restored and that the stream is properly reused, not recreated per entry.
This restores the contiguous streaming behavior that existed before 0.41.0.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.