-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: BinaryReader.ReadExactly #101614
Comments
Tagging subscribers to this area: @dotnet/area-system-io |
This would be equivalent to calling |
Logically yes, but practically the challenge is that the reader has its own buffer. By passing that would be problematic. |
The proposal LGTM, I've marked it as ready for review. |
namespace System.IO;
public partial class BinaryReader
{
public virtual void ReadExactly(Span<byte> buffer);
} |
The method return type is missing (I'm assuming it should be |
LOL. Look, I only work here. Fixed. |
It used to have it's own buffer, after #80331 it does not. I've marked this issue as "help wanted" and "good first issue" to attract some new contributors (any .NET Team member who whishes to contribute please wait for a PR from community and review it, it's the best way you can help). The person who wishes to work on this issue should let others know here, so there are no multiple contributors working on the same problem. Here are some tips that you may find useful:
.\build.cmd -c Release -subset clr+libs+libs.tests
.\build.cmd -c Release -subset clr.corelib+clr.nativecorelib+libs.PreTest && .\dotnet.cmd build -c Release .\src\libraries\System.Runtime\System.Runtime.sln && .\dotnet.cmd build -c Release .\src\libraries\System.Runtime\tests\System.IO.Tests\System.IO.Tests.csproj /t:Test Good luck! |
I would like to attempt providing an implementation for this proposal, if I may have the chance. |
Implements the BinaryReader.ReadExactly method, as proposed in dotnet#101614 Fix dotnet#101614
Background and motivation
When reading custom binary formats one very often needs a specific number of bytes. The existing
Read()
method doesn't read a specific number of bytes, it reads as many bytes are currently available. Calling code has to handle this.We had the same issue on
Stream
and solved this by exposingStream.ReadExactly
andStream.ReadAtLeast
.API Proposal
API Usage
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: