We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Azure.Core
BinaryData.FromStream does a copy so its is faster to use the ReadOnlyMemory overload instead.
MemoryStream stream = GetWrittenStream(); BinaryData data = new BinaryData(stream.GetBuffer().AsMemory(0, (int)stream.Position))
The issue with the above code is stream position is a long and memory wants an int. We need to check for this like this.
MemoryStream stream = GetWrittenStream(); BinaryData data = stream.Position > int.MaxValue ? BinaryData.FromStream(stream) : new BinaryData(stream.GetBuffer().AsMemory(0, (int)stream.Position));
BinaryData.FromStream currently will throw if length is too long if we want to throw or we can do the following
MemoryStream stream = GetWrittenStream(); BinaryData data = stream.Position > int.MaxValue ? new BinaryData(stream.ToArray()) : new BinaryData(stream.GetBuffer().AsMemory(0, (int)stream.Position));
The reason for the else is we only want to take the perf hit when the length is larger that max int.
The question is should we provide a helper for this to avoid accidently doing a sub optimal thing.
The text was updated successfully, but these errors were encountered:
Why not make a PR to BinaryData in the dotnet/runtime repo?
Sorry, something went wrong.
No branches or pull requests
Library name
Azure.Core
Please describe the feature.
BinaryData.FromStream does a copy so its is faster to use the ReadOnlyMemory overload instead.
The issue with the above code is stream position is a long and memory wants an int. We need to check for this like this.
BinaryData.FromStream currently will throw if length is too long if we want to throw or we can do the following
The reason for the else is we only want to take the perf hit when the length is larger that max int.
The question is should we provide a helper for this to avoid accidently doing a sub optimal thing.
The text was updated successfully, but these errors were encountered: