[PR #930] [MERGED] Added IStreamStack for debugging and configurable buffer management. … #1353

Closed
opened 2026-01-29 22:20:08 +00:00 by claunia · 0 comments
Owner

📋 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: masterHead: feature/StreamStack


📝 Commits (9)

  • 21f14cd Added IStreamStack for debugging and configurable buffer management. Added SharpCompressStream to consolodate streams to help simplify debugging. All unit tests passing.
  • f37bebe Merge branch 'master' into feature/StreamStack
  • 9387757 Formated with Sharpier.
  • 5fe9516 Various copilot suggestions. Tests still passing.
  • 8575e56 Formatting fix.
  • 587675e Fixed some missing features caused by merging an earlier branch than required.
  • 60d5955 Final tidy.
  • 236e653 Merge branch 'master' into feature/StreamStack
  • 893890c Merge 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

  • Universal Design Philosophy: Implemented as an interface rather than base class to allow anything to join the stack, not necessarily just streams, while keeping the chain intact
  • Flexible Architecture: Any object can participate in the stream hierarchy by implementing IStreamStack
  • Buffer Management: BufferSize, BufferPosition, DefaultBufferSize properties for systematic buffer placement
  • Debug Support: InstanceId for comprehensive stream tracking (DEBUG_STREAMS only - zero release impact)
  • Chain Integrity: BaseStream() method maintains hierarchy navigation regardless of implementation type

2. Unified SharpCompressStream

Consolidates the functionality of NonDisposingStream, RewindableStream and CountingWritableSubStream into a single implementation. Future refactors could simplify things further. SharpCompressStream provides:

  • Over-read Protection: Fixed-size buffers safely contain over-read data
  • Position Tracking: Internal position management independent of base stream
  • Stream Resumption: Buffer rewinding (via fixed buffer that be proficed by a base stream/IStreamStack item) allows base streams to resume at exact boundaries
  • Lifecycle Management: Configurable disposal behavior

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:

FileStream[Px0::]/SharpCompressStream#1[Px0:Bx0:Dx0] : Constructed by [Volume..ctor()]
FileStream[Px21e::]/SharpCompressStream#1[Px25:Bx10000:Dx10000]/ZlibBaseStream#2[:Bx0] : Constructed by [ZipFilePart.CreateDecompressionStream()]
FileStream[Px21e::]/SharpCompressStream#1[Px25:Bx10000:Dx10000]/ZlibBaseStream#2[:Bx0]/DeflateStream#3[Px0:Bx0:Dx0] : Constructed by [StreamingZipFilePart.GetCompressedStream()]
FileStream[Px21e::]/SharpCompressStream#1[Px25:Bx10000:Dx10000]/ZlibBaseStream#2[:Bx0]/DeflateStream#3[Px0:Bx0:Dx0]/SharpCompressStream#4[Px0:Bx0:Dx0] : Constructed by [StreamingZipFilePart.GetCompressedStream()]
FileStream[Px21e::]/SharpCompressStream#1[Px25:Bx10000:Dx10000]/ZlibBaseStream#2[:Bx0]/DeflateStream#3[Px0:Bx0:Dx0]/SharpCompressStream#4[Px0:Bx0:Dx0]/EntryStream#5[Px0:Bx0:Dx0] : Constructed by [AbstractReader`2.GetEntryStream()]
FileStream[Px21e::]/SharpCompressStream#1[Px28:Bx10000:Dx10000]/ZlibBaseStream#2[:Bx0]/DeflateStream#3[Px3:Bx0:Dx0]/SharpCompressStream#4[Px1:Bx0:Dx0]/EntryStream#5[Px1:Bx0:Dx0] : Disposed by [ZipReaderTests.Issue_685()]
FileStream[Px21e::]/SharpCompressStream#1[Px28:Bx10000:Dx10000]/ZlibBaseStream#2[:Bx0]/DeflateStream#3[Px3:Bx0:Dx0]/SharpCompressStream#4[Px1:Bx0:Dx0] : Disposed by [EntryStream.Dispose()]
FileStream[Px21e::]/SharpCompressStream#1[Px5e:Bx10000:Dx10000]/ZlibBaseStream#6[:Bx0] : Constructed by [ZipFilePart.CreateDecompressionStream()]
FileStream[Px21e::]/SharpCompressStream#1[Px5e:Bx10000:Dx10000]/ZlibBaseStream#6[:Bx0]/DeflateStream#7[Px0:Bx0:Dx0] : Constructed by [StreamingZipFilePart.GetCompressedStream()]
FileStream[Px21e::]/SharpCompressStream#1[Px5e:Bx10000:Dx10000]/ZlibBaseStream#6[:Bx0]/DeflateStream#7[Px0:Bx0:Dx0]/SharpCompressStream#8[Px0:Bx0:Dx0] : Constructed by [StreamingZipFilePart.GetCompressedStream()]
FileStream[Px21e::]/SharpCompressStream#1[Px5e:Bx10000:Dx10000]/ZlibBaseStream#6[:Bx0]/DeflateStream#7[Px0:Bx0:Dx0]/SharpCompressStream#8[Px0:Bx0:Dx0]/EntryStream#9[Px0:Bx0:Dx0] : Constructed by [AbstractReader`2.GetEntryStream()]
FileStream[Px21e::]/SharpCompressStream#1[Px62:Bx10000:Dx10000]/ZlibBaseStream#6[:Bx0]/DeflateStream#7[Px4:Bx0:Dx0]/SharpCompressStream#8[Px2:Bx0:Dx0]/EntryStream#9[Px2:Bx0:Dx0] : Disposed by [ZipReaderTests.Issue_685()]
FileStream[Px21e::]/SharpCompressStream#1[Px62:Bx10000:Dx10000]/ZlibBaseStream#6[:Bx0]/DeflateStream#7[Px4:Bx0:Dx0]/SharpCompressStream#8[Px2:Bx0:Dx0] : Disposed by [EntryStream.Dispose()]
FileStream[Px21e::]/SharpCompressStream#1[Px9f:Bx10000:Dx10000]/ReadOnlySubStream#10[Px0:Bx0:Dx0] : Constructed by [ZipFilePart.GetCryptoStream()]
FileStream[Px21e::]/SharpCompressStream#1[Px9f:Bx10000:Dx10000]/ReadOnlySubStream#10[Px0:Bx0:Dx0]/EntryStream#11[Px0:Bx0:Dx0] : Constructed by [AbstractReader`2.GetEntryStream()]
FileStream[Px21e::]/SharpCompressStream#1[Pxa1:Bx10000:Dx10000]/ReadOnlySubStream#10[Px2:Bx0:Dx0]/EntryStream#11[Px2:Bx0:Dx0] : Disposed by [ZipReaderTests.Issue_685()]
FileStream[Px21e::]/SharpCompressStream#1[Pxa1:Bx10000:Dx10000]/ReadOnlySubStream#10[Px2:Bx0:Dx0] : Disposed by [EntryStream.Dispose()]
FileStream[Px21e::]/SharpCompressStream#1[Pxcd:Bx10000:Dx10000]/ReadOnlySubStream#12[Px0:Bx0:Dx0] : Constructed by [ZipFilePart.GetCryptoStream()]
FileStream[Px21e::]/SharpCompressStream#1[Pxcd:Bx10000:Dx10000]/ReadOnlySubStream#12[Px0:Bx0:Dx0]/EntryStream#13[Px0:Bx0:Dx0] : Constructed by [AbstractReader`2.GetEntryStream()]
FileStream[Px21e::]/SharpCompressStream#1[Pxdc:Bx10000:Dx10000]/ReadOnlySubStream#12[Pxf:Bx0:Dx0]/EntryStream#13[Pxf:Bx0:Dx0] : Disposed by [ZipReaderTests.Issue_685()]
FileStream[Px21e::]/SharpCompressStream#1[Pxdc:Bx10000:Dx10000]/ReadOnlySubStream#12[Pxf:Bx0:Dx0] : Disposed by [EntryStream.Dispose()]
FileStream[Px21e::]/SharpCompressStream#1[Px21e:Bx10000:Dx10000] : Disposed by [Volume.Dispose()]

Key Insights from This Debug Output:

  • Position Progression: Watch SharpCompressStream#1 position increment (Px0Px25Px28Px5ePx62) as it processes ZIP entries etc
  • Buffer Management: Bx10000 (64KB configurable buffer) strategically placed at base level for over-reading protection
  • Stream Lifecycle: Complex multi-layered hierarchies created and properly disposed for each ZIP entry
  • Over-reading Safety: Base FileStream position remains stable while compression streams process data safely

Format: StreamType#InstanceId[Position:BufferSize:DefaultBufferSize]

📈 Benefits

Changes

  • Simplifies over-reading in Deflate, Zlib, Gzip, Lzma etc. Streams can return/rewind unused bytes by repositioning the base buffer
  • Predictable memory usage with fixed-size buffers
  • Enhanced debugging with complete stream hierarchy visibility (debug builds only)

Strategic Foundation

  • Flexible Architecture: Interface-based design allows any object to join stream hierarchies
  • Clean foundation for consolidating additional stream types in future phases
  • Proven approach validates core functionality before broader changes
  • Full backward compatibility ensures existing code works unchanged

🧪 Usage

// Automatic over-reading protection
var options = new ReaderOptions() { BufferSize = 0x10000 }; // 64KB
using var stream = SharpCompressStream.Create(baseStream, bufferSize: options.BufferSize);

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.

## 📋 Pull Request Information **Original PR:** https://github.com/adamhathcock/sharpcompress/pull/930 **Author:** [@Nanook](https://github.com/Nanook) **Created:** 7/20/2025 **Status:** ✅ Merged **Merged:** 7/23/2025 **Merged by:** [@adamhathcock](https://github.com/adamhathcock) **Base:** `master` ← **Head:** `feature/StreamStack` --- ### 📝 Commits (9) - [`21f14cd`](https://github.com/adamhathcock/sharpcompress/commit/21f14cd3f21c3e234b12c71de4895172034d8279) Added IStreamStack for debugging and configurable buffer management. Added SharpCompressStream to consolodate streams to help simplify debugging. All unit tests passing. - [`f37bebe`](https://github.com/adamhathcock/sharpcompress/commit/f37bebe51f9f402455c8159571ccb5c44c2195c3) Merge branch 'master' into feature/StreamStack - [`9387757`](https://github.com/adamhathcock/sharpcompress/commit/938775789db014f01719648d21f404b824cac8e6) Formated with Sharpier. - [`5fe9516`](https://github.com/adamhathcock/sharpcompress/commit/5fe9516c09343238940bc80f7b0eb07d226a9463) Various copilot suggestions. Tests still passing. - [`8575e56`](https://github.com/adamhathcock/sharpcompress/commit/8575e5615dd6762b217cc416209987f5ec11d065) Formatting fix. - [`587675e`](https://github.com/adamhathcock/sharpcompress/commit/587675e488d43ab5f04e1e96490fd3686180de5b) Fixed some missing features caused by merging an earlier branch than required. - [`60d5955`](https://github.com/adamhathcock/sharpcompress/commit/60d595510176c0a3c164a55561303a720ae4ba0e) Final tidy. - [`236e653`](https://github.com/adamhathcock/sharpcompress/commit/236e6531761ddc517be67244d1259fd3f07d17d0) Merge branch 'master' into feature/StreamStack - [`893890c`](https://github.com/adamhathcock/sharpcompress/commit/893890c9851764e9112f3e32bf1efb247458a15e) Merge branch 'master' into feature/StreamStack ### 📊 Changes **84 files changed** (+2336 additions, -486 deletions) <details> <summary>View changed files</summary> 📝 `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_ </details> ### 📄 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 - **Universal Design Philosophy**: Implemented as an interface rather than base class to allow **anything to join the stack**, not necessarily just streams, while keeping the chain intact - **Flexible Architecture**: Any object can participate in the stream hierarchy by implementing `IStreamStack` - **Buffer Management**: `BufferSize`, `BufferPosition`, `DefaultBufferSize` properties for systematic buffer placement - **Debug Support**: `InstanceId` for comprehensive stream tracking (DEBUG_STREAMS only - zero release impact) - **Chain Integrity**: `BaseStream()` method maintains hierarchy navigation regardless of implementation type ### 2. Unified SharpCompressStream Consolidates the functionality of NonDisposingStream, RewindableStream and CountingWritableSubStream into a single implementation. Future refactors could simplify things further. SharpCompressStream provides: - **Over-read Protection**: Fixed-size buffers safely contain over-read data - **Position Tracking**: Internal position management independent of base stream - **Stream Resumption**: Buffer rewinding (via fixed buffer that be proficed by a base stream/IStreamStack item) allows base streams to resume at exact boundaries - **Lifecycle Management**: Configurable disposal behavior ### 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: ``` FileStream[Px0::]/SharpCompressStream#1[Px0:Bx0:Dx0] : Constructed by [Volume..ctor()] FileStream[Px21e::]/SharpCompressStream#1[Px25:Bx10000:Dx10000]/ZlibBaseStream#2[:Bx0] : Constructed by [ZipFilePart.CreateDecompressionStream()] FileStream[Px21e::]/SharpCompressStream#1[Px25:Bx10000:Dx10000]/ZlibBaseStream#2[:Bx0]/DeflateStream#3[Px0:Bx0:Dx0] : Constructed by [StreamingZipFilePart.GetCompressedStream()] FileStream[Px21e::]/SharpCompressStream#1[Px25:Bx10000:Dx10000]/ZlibBaseStream#2[:Bx0]/DeflateStream#3[Px0:Bx0:Dx0]/SharpCompressStream#4[Px0:Bx0:Dx0] : Constructed by [StreamingZipFilePart.GetCompressedStream()] FileStream[Px21e::]/SharpCompressStream#1[Px25:Bx10000:Dx10000]/ZlibBaseStream#2[:Bx0]/DeflateStream#3[Px0:Bx0:Dx0]/SharpCompressStream#4[Px0:Bx0:Dx0]/EntryStream#5[Px0:Bx0:Dx0] : Constructed by [AbstractReader`2.GetEntryStream()] FileStream[Px21e::]/SharpCompressStream#1[Px28:Bx10000:Dx10000]/ZlibBaseStream#2[:Bx0]/DeflateStream#3[Px3:Bx0:Dx0]/SharpCompressStream#4[Px1:Bx0:Dx0]/EntryStream#5[Px1:Bx0:Dx0] : Disposed by [ZipReaderTests.Issue_685()] FileStream[Px21e::]/SharpCompressStream#1[Px28:Bx10000:Dx10000]/ZlibBaseStream#2[:Bx0]/DeflateStream#3[Px3:Bx0:Dx0]/SharpCompressStream#4[Px1:Bx0:Dx0] : Disposed by [EntryStream.Dispose()] FileStream[Px21e::]/SharpCompressStream#1[Px5e:Bx10000:Dx10000]/ZlibBaseStream#6[:Bx0] : Constructed by [ZipFilePart.CreateDecompressionStream()] FileStream[Px21e::]/SharpCompressStream#1[Px5e:Bx10000:Dx10000]/ZlibBaseStream#6[:Bx0]/DeflateStream#7[Px0:Bx0:Dx0] : Constructed by [StreamingZipFilePart.GetCompressedStream()] FileStream[Px21e::]/SharpCompressStream#1[Px5e:Bx10000:Dx10000]/ZlibBaseStream#6[:Bx0]/DeflateStream#7[Px0:Bx0:Dx0]/SharpCompressStream#8[Px0:Bx0:Dx0] : Constructed by [StreamingZipFilePart.GetCompressedStream()] FileStream[Px21e::]/SharpCompressStream#1[Px5e:Bx10000:Dx10000]/ZlibBaseStream#6[:Bx0]/DeflateStream#7[Px0:Bx0:Dx0]/SharpCompressStream#8[Px0:Bx0:Dx0]/EntryStream#9[Px0:Bx0:Dx0] : Constructed by [AbstractReader`2.GetEntryStream()] FileStream[Px21e::]/SharpCompressStream#1[Px62:Bx10000:Dx10000]/ZlibBaseStream#6[:Bx0]/DeflateStream#7[Px4:Bx0:Dx0]/SharpCompressStream#8[Px2:Bx0:Dx0]/EntryStream#9[Px2:Bx0:Dx0] : Disposed by [ZipReaderTests.Issue_685()] FileStream[Px21e::]/SharpCompressStream#1[Px62:Bx10000:Dx10000]/ZlibBaseStream#6[:Bx0]/DeflateStream#7[Px4:Bx0:Dx0]/SharpCompressStream#8[Px2:Bx0:Dx0] : Disposed by [EntryStream.Dispose()] FileStream[Px21e::]/SharpCompressStream#1[Px9f:Bx10000:Dx10000]/ReadOnlySubStream#10[Px0:Bx0:Dx0] : Constructed by [ZipFilePart.GetCryptoStream()] FileStream[Px21e::]/SharpCompressStream#1[Px9f:Bx10000:Dx10000]/ReadOnlySubStream#10[Px0:Bx0:Dx0]/EntryStream#11[Px0:Bx0:Dx0] : Constructed by [AbstractReader`2.GetEntryStream()] FileStream[Px21e::]/SharpCompressStream#1[Pxa1:Bx10000:Dx10000]/ReadOnlySubStream#10[Px2:Bx0:Dx0]/EntryStream#11[Px2:Bx0:Dx0] : Disposed by [ZipReaderTests.Issue_685()] FileStream[Px21e::]/SharpCompressStream#1[Pxa1:Bx10000:Dx10000]/ReadOnlySubStream#10[Px2:Bx0:Dx0] : Disposed by [EntryStream.Dispose()] FileStream[Px21e::]/SharpCompressStream#1[Pxcd:Bx10000:Dx10000]/ReadOnlySubStream#12[Px0:Bx0:Dx0] : Constructed by [ZipFilePart.GetCryptoStream()] FileStream[Px21e::]/SharpCompressStream#1[Pxcd:Bx10000:Dx10000]/ReadOnlySubStream#12[Px0:Bx0:Dx0]/EntryStream#13[Px0:Bx0:Dx0] : Constructed by [AbstractReader`2.GetEntryStream()] FileStream[Px21e::]/SharpCompressStream#1[Pxdc:Bx10000:Dx10000]/ReadOnlySubStream#12[Pxf:Bx0:Dx0]/EntryStream#13[Pxf:Bx0:Dx0] : Disposed by [ZipReaderTests.Issue_685()] FileStream[Px21e::]/SharpCompressStream#1[Pxdc:Bx10000:Dx10000]/ReadOnlySubStream#12[Pxf:Bx0:Dx0] : Disposed by [EntryStream.Dispose()] FileStream[Px21e::]/SharpCompressStream#1[Px21e:Bx10000:Dx10000] : Disposed by [Volume.Dispose()] ``` **Key Insights from This Debug Output:** - **Position Progression**: Watch `SharpCompressStream#1` position increment (`Px0` → `Px25` → `Px28` → `Px5e` → `Px62`) as it processes ZIP entries etc - **Buffer Management**: `Bx10000` (64KB configurable buffer) strategically placed at base level for over-reading protection - **Stream Lifecycle**: Complex multi-layered hierarchies created and properly disposed for each ZIP entry - **Over-reading Safety**: Base FileStream position remains stable while compression streams process data safely **Format**: `StreamType#InstanceId[Position:BufferSize:DefaultBufferSize]` ## 📈 Benefits ### Changes - **Simplifies over-reading** in Deflate, Zlib, Gzip, Lzma etc. Streams can return/rewind unused bytes by repositioning the base buffer - **Predictable memory usage** with fixed-size buffers - **Enhanced debugging** with complete stream hierarchy visibility (debug builds only) ### Strategic Foundation - **Flexible Architecture**: Interface-based design allows any object to join stream hierarchies - **Clean foundation** for consolidating additional stream types in future phases - **Proven approach** validates core functionality before broader changes - **Full backward compatibility** ensures existing code works unchanged ## 🧪 Usage ```csharp // Automatic over-reading protection var options = new ReaderOptions() { BufferSize = 0x10000 }; // 64KB using var stream = SharpCompressStream.Create(baseStream, bufferSize: options.BufferSize); ``` **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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 22:20:08 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1353