mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-03 21:23:38 +00:00
[PR #930] [MERGED] Added IStreamStack for debugging and configurable buffer management. … #1353
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/adamhathcock/sharpcompress/pull/930
Author: @Nanook
Created: 7/20/2025
Status: ✅ Merged
Merged: 7/23/2025
Merged by: @adamhathcock
Base:
master← Head:feature/StreamStack📝 Commits (9)
21f14cdAdded IStreamStack for debugging and configurable buffer management. Added SharpCompressStream to consolodate streams to help simplify debugging. All unit tests passing.f37bebeMerge branch 'master' into feature/StreamStack9387757Formated with Sharpier.5fe9516Various copilot suggestions. Tests still passing.8575e56Formatting fix.587675eFixed some missing features caused by merging an earlier branch than required.60d5955Final tidy.236e653Merge branch 'master' into feature/StreamStack893890cMerge branch 'master' into feature/StreamStack📊 Changes
84 files changed (+2336 additions, -486 deletions)
View changed files
📝
src/SharpCompress/Archives/ArchiveFactory.cs(+13 -4)📝
src/SharpCompress/Archives/AutoArchiveFactory.cs(+6 -3)📝
src/SharpCompress/Archives/GZip/GZipWritableArchiveEntry.cs(+1 -1)📝
src/SharpCompress/Archives/Tar/TarWritableArchiveEntry.cs(+1 -1)📝
src/SharpCompress/Archives/Zip/ZipArchive.cs(+32 -7)📝
src/SharpCompress/Archives/Zip/ZipWritableArchiveEntry.cs(+1 -1)📝
src/SharpCompress/Common/EntryStream.cs(+44 -2)📝
src/SharpCompress/Common/Tar/TarReadOnlySubStream.cs(+30 -3)📝
src/SharpCompress/Common/Volume.cs(+5 -1)📝
src/SharpCompress/Common/Zip/PkwareTraditionalCryptoStream.cs(+29 -1)📝
src/SharpCompress/Common/Zip/StreamingZipFilePart.cs(+4 -3)📝
src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs(+29 -32)📝
src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs(+29 -1)📝
src/SharpCompress/Common/Zip/ZipFilePart.cs(+2 -2)📝
src/SharpCompress/Compressors/ADC/ADCStream.cs(+29 -2)📝
src/SharpCompress/Compressors/ArcLzw/ArcLzwStream.cs(+33 -1)📝
src/SharpCompress/Compressors/BZip2/BZip2Stream.cs(+29 -2)📝
src/SharpCompress/Compressors/BZip2/CBZip2InputStream.cs(+29 -1)📝
src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs(+29 -1)📝
src/SharpCompress/Compressors/Deflate/DeflateStream.cs(+34 -2)...and 64 more files
📄 Description
IStreamStack Buffering Enhancement
This pull request introduces a comprehensive buffer management stack that simplifies stream over-reading in compression formats, adds optional stream hierarchy debugging with position tracking (no release performance impact), and establishes a clean foundation for future stream consolidation and simplification.
Warning: This is a fundamental change and needs to be looked over carefully. It was born from having a lot of difficulty debugging stream positions and rewinding. A lot of the files changed are to add a StreamStack interface, other changes are to cater for SharpCompressStream and buffer usage. All unit tests are passing with minimal or zero change.
🔧 Core Changes
1. Enhanced IStreamStack Interface
IStreamStackBufferSize,BufferPosition,DefaultBufferSizeproperties for systematic buffer placementInstanceIdfor comprehensive stream tracking (DEBUG_STREAMS only - zero release impact)BaseStream()method maintains hierarchy navigation regardless of implementation type2. Unified SharpCompressStream
Consolidates the functionality of NonDisposingStream, RewindableStream and CountingWritableSubStream into a single implementation. Future refactors could simplify things further. SharpCompressStream provides:
3. 🔍 DEBUG_STREAMS C# define for Debugging Visualization
Activated for .NET 8.0 Debug builds only, provides complete stream hierarchy tracking with zero performance impact on release builds:
Key Insights from This Debug Output:
SharpCompressStream#1position increment (Px0→Px25→Px28→Px5e→Px62) as it processes ZIP entries etcBx10000(64KB configurable buffer) strategically placed at base level for over-reading protectionFormat:
StreamType#InstanceId[Position:BufferSize:DefaultBufferSize]📈 Benefits
Changes
Strategic Foundation
🧪 Usage
Result: Compression streams can over-read safely into managed buffers, then rewind to exact boundaries, allowing base streams to resume correctly for subsequent processing.
This enhancement introduces a comprehensive buffer management stack that solves fundamental stream processing issues while providing optional debugging capabilities with zero release performance impact. The flexible interface-based design allows any object to participate in stream hierarchies, creating a solid foundation for future consolidation phases.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.