-
Notifications
You must be signed in to change notification settings - Fork 353
Flesh out ByteRangeStream methods to make it always limit reads
#213
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
Conversation
|
FYI @stephentoub |
| { | ||
| long effectiveCount = Math.Min(count, _totalCount - _currentCount); | ||
| if (effectiveCount > 0) | ||
| // A negative count causes base.Raad* methods to throw an ArgumentOutOfRangeException. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrote method because _currentCount may now exceed _totalCount and we need to distinguish that case (a no-op) from count < 0 (an error).
| _currentCount = offset; | ||
| break; | ||
| case SeekOrigin.Current: | ||
| _currentCount = unchecked(_currentCount + offset); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/unchecked:
Expressions that contain non-constant terms are unchecked by default at compile time and run time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That said, seems you don't need the unchecked context here.
mkArtakMSFT
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a comment regarding the unchecked context. The rest looks good.
- #206 - `Seek(...)` was a no-op, `Position` was incorrect if `_lowerbounds != 0`, `ReadAsync(...)` read entire inner `Stream` - rewrite `ByteRangeStreamTest` to cover new `ByteRangeStream` members and hold fewer resources - remove `DelegatingStream.CopyToAsync(...)` override because it copied entire inner `Stream` and was not needed - base implementation invokes `ReadAsync(...)`
2d675b0 to
ca41472
Compare
|
🆙📅 to rebase and address @mkArtakMSFT's comment. |
ByteRangeStreamdoes not limitCopyToAsync(...)range as it should #206Seek(...)was a no-op,Positionwas incorrect if_lowerbounds != 0,ReadAsync(...)read entire innerStreamByteRangeStreamTestto cover newByteRangeStreammembers and hold fewer resourcesDelegatingStream.CopyToAsync(...)override because it copied entire innerStreamand was not neededReadAsync(...)