mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-04-09 15:43:22 +00:00
[PR #1160] [MERGED] add check to see if we need to seek before hand #1594
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/1160
Author: @adamhathcock
Created: 1/26/2026
Status: ✅ Merged
Merged: 1/26/2026
Merged by: @adamhathcock
Base:
release← Head:adam/check-if-seek📝 Commits (8)
44e4b18add check to see if we need to seek before handa82fda9more testing and add pooling to cacheddf37e8Initial plan8c95f86do CanSeek first875c2d7Fix BufferedSubStream double-dispose issue with ArrayPoola0af060Add disposal checks to RefillCache methods56d3091Fix condition order to check CanSeek before Position7dcc13cMerge pull request #1161 from adamhathcock/copilot/sub-pr-1160📊 Changes
3 files changed (+74 additions, -12 deletions)
View changed files
📝
src/SharpCompress/IO/BufferedSubStream.cs(+44 -10)📝
src/SharpCompress/IO/SharpCompressStream.cs(+0 -1)📝
tests/SharpCompress.Test/Streams/SharpCompressStreamTest.cs(+30 -1)📄 Description
Related to findings on https://github.com/adamhathcock/sharpcompress/issues/1105 by @julianxhokaxhiu
This pull request improves memory efficiency and stream handling in
BufferedSubStreamby using pooled buffers and optimizing seek operations. It also updates the test suite to better simulate forward-only stream scenarios.Memory Management Improvements:
_cacheallocation inBufferedSubStreamto useArrayPool<byte>.Shared.Rentfor buffer pooling, and ensured the buffer is returned to the pool inDisposefor reduced GC pressure. [1] [2]Performance and Stream Handling Enhancements:
RefillCacheandRefillCacheAsyncto avoid unnecessary seek operations by checking the current stream position before seeking, improving performance for sequential reads. [1] [2]Testing Improvements:
BufferReadAndSeekTestto wrap the memory stream withForwardOnlyStream, better simulating streams that do not support seeking. [1] [2]🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.