Remove ZipHelper.ReadBytes wrapper methods and use Stream.ReadAtLeast directly#118629
Remove ZipHelper.ReadBytes wrapper methods and use Stream.ReadAtLeast directly#118629stephentoub merged 3 commits intomainfrom
Conversation
…vior Co-authored-by: rzikm <[email protected]>
There was a problem hiding this comment.
Pull Request Overview
This PR simplifies the ZipHelper.ReadBytes and ZipHelper.ReadBytesAsync methods by leveraging the built-in EOF handling of Stream.ReadAtLeast instead of manually checking for end-of-stream conditions and throwing exceptions.
Key changes:
- Removes manual EOF checking and exception throwing logic
- Uses
throwOnEndOfStream: trueparameter to letReadAtLeasthandle EOF scenarios automatically - Changes exception type from
IOExceptiontoEndOfStreamExceptionfor EOF conditions
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| ZipHelper.cs | Simplified ReadBytes method by removing manual EOF check and using built-in ReadAtLeast exception handling |
| ZipHelper.Async.cs | Simplified ReadBytesAsync method with the same approach as the synchronous version |
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
src/libraries/System.IO.Compression/src/System/IO/Compression/ZipHelper.Async.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/ZipHelper.cs
Outdated
Show resolved
Hide resolved
|
@copilot, please address my feedback. |
|
I'd like to mention that it might be a breaking change. We throw different type of exception than before. Probability of breaking someone is small here, but still... |
It used to throw IOException and now it'll throw EndOfStreamException... which is an IOException. While it can affect someone who's doing an exact type test, we generally don't consider throwing a more derived type to be "breaking". |
… directly Co-authored-by: stephentoub <[email protected]>
This PR removes the unnecessary
ZipHelper.ReadBytesandZipHelper.ReadBytesAsyncwrapper methods and replaces all call sites with direct calls toStream.ReadAtLeastandStream.ReadAtLeastAsync.Changes Made
Before:
After:
Benefits
Stream.ReadAtLeastmethods is more straightforwardStream.ReadAtLeastthroughout the codebaseBackward Compatibility
The change maintains functional compatibility because the behavior is identical - all call sites now use
Stream.ReadAtLeastwiththrowOnEndOfStream: true, which is exactly what the wrapper methods were doing.All existing tests (1329) continue to pass, confirming no behavioral changes.
Addresses feedback from @stephentoub in #111679.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.